Wednesday, 24 June 2015

Prevent browser from loading drag and dropped file

I've been implementing a drag-and-drop uploader today but found that if the user missed the drop area the browser would load the file directly. Annoying huh? I overcame this with this nifty bit of javascript:
window.addEventListener("dragover",function(e){
  e = e || event;
  e.preventDefault();
},false);
window.addEventListener("drop",function(e){
  e = e || event;
  e.preventDefault();
},false);

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!