Crossbrowser method to cancel the drop event in the contents of an edittable div

I want to remove images (and other things) from being deleted in editable content div in browsers. I see how to do this for Chrome and IE. Firefox stubbornly refuses. The code snippet http://jsbin.com/oqozo3 shows an example showing that the event is firing, I cancel it, and in FF the image still appears,

Basically, the following does not work in FF

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ContentEditable fails in FF</title>
<script type="text/javascript">
function init() {
  var target = document.getElementById("target");
  if (target.addEventListener) {
    target.addEventListener ("dragenter", all, false);
    target.addEventListener ("dragover", all, false);
    target.addEventListener ("drop", all, false);    
    target.addEventListener ("dragdrop", all, false);
  } else {
    target.attachEvent ("ondragenter", all, false);
    target.attachEvent ("ondragover", all, false);
    target.attachEvent ("ondrop", all, false);    
  }
}
function all(event) {
if (event.preventDefault) { event.preventDefault();} 
return false;
}
</script>
</head>
<body onLoad="init();">
    <div id="target" style="border: 1px solid black; height: 100px;" contenteditable="true">This is editable content</div>
    <div>
     <p>I don't want the image to be draggable to the above div. Works in IE,
     Chrome, not firefox.</p>
     <img src="http://mozcom-cdn.mozilla.net/img/firefox-100.jpg">
    </div>
</body>
</html>

I already examined: ContentEditable DIV - disabling drag and drop , but suggestions there also don't work in firefox.

+3
source share
1 answer

, jQuery, , -

0

Source: https://habr.com/ru/post/1776508/


All Articles