Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable File drag & drop if there isn't a file input

I think the solution to this is staring me in the face, but I can't seem to find it.

So, I'm making a site that has a small file upload section. The upload section will have a place to upload an image for different devices and device orientations (i.e. iPhone, iPad, portrait and landscape). I can easily figure out how to implement the drag & drop on the individual device icons, but if the user misses the drop area, the browser will just navigate to that image on their system. How do I disable drag & drop if there isn't a file input type to receive the dragged file?

like image 880
CJT3 Avatar asked Oct 26 '12 06:10

CJT3


People also ask

How do I cancel drag and drop?

Ever found yourself changing your mind about dragging and dropping a file? The problem is that if you let go of the file, it'll be moved or copied to wherever your mouse is hovering over. To cancel drag and drop, either hit Esc or drag the file to the menu bar at the top of the screen and release.

How do I stop drag and drop text?

In the right pane of the “Word Options” window, you will see an “Editing Options” section. In this section, disable the “Allow text to be dragged and dropped” option. Then, at the bottom of the “Word Options” window, click “OK.”


1 Answers

This document (documentation for a jQuery file upload plugin) shows how to disable the browser's default action: https://github.com/blueimp/jQuery-File-Upload/wiki/Drop-zone-effects

Quoting the document:

If you want to allow specific drop zones but disable the default browser action for file drops on the document, add the following JavaScript code:

$(document).bind('drop dragover', function (e) {
     e.preventDefault();
});

Note that preventing the default action for both the "drop" and "dragover" events is required to disable the default browser drop action.

like image 135
John Dvorak Avatar answered Sep 20 '22 05:09

John Dvorak