Created
January 23, 2015 07:11
-
-
Save jsliang/21a099550aa9ac9e498c to your computer and use it in GitHub Desktop.
preventing drag & drop disaster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// preventing drag & drop disaster | |
var preventDrag = function(e) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
}; | |
var preventDrop = function(e) { | |
if (e.dataTransfer.files.length > 0) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
} | |
}; | |
window.document.addEventListener('dragenter', preventDrag, false); | |
window.document.addEventListener('dragover', preventDrag, false); | |
window.document.addEventListener('drop', preventDrop, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment