2

I want to prevent pictures from being pasted into a content editable <div>. I have already tried the following but it doesn't filter out pictures, it only removes the styling of words.

div.addEventListener("paste", e => {
    e.preventDefault();
    let text = (e.originalEvent || e).clipboardData.getData('text/plain');
    document.execCommand("insertHTML", false, text);
});

How can i prevent it from happening without using the HTML textarea element? Thanks in advance

Nicolas
  • 97
  • 7
  • 1
    This question seems specific and the questions marked as duplicate don't seem to specifically answer this question. As I cannot add an answer, I'm pasting my solution: `if (event.clipboardData.types.includes('Files')) event.preventDefault()` – Krishna Pravin Jan 05 '21 at 12:49

0 Answers0