I am dragging images from another browser tab to the tab of my web page. My event handlers for the drop event work in any desktop browser other than Internet Explorer 11.
IE just jumps to the URL of the image that I dropped, instead of firing the drop event and letting my JS code do what it wants with it (like it does in Chrome, Firefox, Opera and Safari, in Windows 7). The code is below. Please note: none of the warnings listed in the code light up.
I even followed the recommendations on the Microsoft page here: https://msdn.microsoft.com/en-us/library/ms536929(v=vs.85).aspx regarding undoing the default dragenter and window.event.returnValue=false instructions window.event.returnValue=false in the ondragenter and ondragover "event handlers (note: other browsers did not require me to have a dragenter event handler)
$(window).on("dragenter", function(event) { alert('drag enter'); event.returnValue = false; event.preventDefault(); event.stopPropagation(); }); $(window).on("dragover", function(event) { alert('drag over'); event.returnValue = false; event.preventDefault(); event.stopPropagation(); }); $(window).on("dragleave", function(event) { alert('drag leave'); event.preventDefault(); event.stopPropagation(); }); $(window).on("drop", function(event) { alert('drop'); event.preventDefault(); event.stopPropagation(); var imageSrc = $(event.originalEvent.dataTransfer.getData('text/html')) .filter(function(i, elm){return $(elm).is('img');}).attr('src');
Thanks so much for any suggestions!
source share