Test if dragenter/dragover Event Contains Files

0
0

HTML5 drag and drop is great for handling file uploads. But if that’s the only thing you are using it for, it’s nice to know if any particular dragenter or dragoverevent actually has files. Unlike, for example, just the dragging of some selected text.

Send the event object to this function and it will return the truth (assuming you are in a browser that supports all this):

function containsFiles(event) {

    if (event.dataTransfer.types) {
        for (var i = 0; i < event.dataTransfer.types.length; i++) {
            if (event.dataTransfer.types[i] == "Files") {
                return true;
            }
        }
    }
    
    return false;

}
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.