I have a simple web app that uses the filereader api in HTML5 to accept file uploads through drag and drop.
Upon dragging a file onto the webpage, the correct drag event will fire, but when I drop the file IE simply opens it rather than letting the JS handle it.
The drop code is very basic:
this.addEventListener("drop", function(event) {
event.stopPropagation();
event.preventDefault();
Self.drop(event); //this event is not hit. IE just opens the file!
}, false);
Is this a specific limitation of IE10 or could I be doing something wrong?
Thanks
You will want to also listen to the
dragenter
anddragover
events and prevent their default behavior. You'll also want to prevent default behavior in thedrop
event handler as well.For example you may want to do something like this...
You can find a working example at this JSFiddle http://jsfiddle.net/qsyNW/
Note: You don't have to use jQuery with this like I did. However, if you do use jQuery then you'll need to reference
e.originalEvent
inside thedrop
event handler in order to get at thedataTransfer.files
.