Drag&Drop : the least obvious way
Posted by assaneonline
Today, playing with my Google Chrome browser (which, btw I do so frequently ;) ) I observered that dragging file from my desktop and dropping them onto a HTML file upload input ( ) was actually selecting the file. In other words, this drag-and-drop is equivalent to clicking the file upload button, browsing the local file explorer and choosing the file. Isn't this great ?
Going beyond this simple observation
After observing this mysterious phenomenon, I wondered if it couldn't be possible to detect this action and submit the form (assuming we have our file upload input wrapped inside a form), having the file sent to the server.
I wrote a simple HTML test file and noticed that binding a handler to a file upload input's onchange event was doing exactly that !
This is my test scripts :
Once you have done this, you can imagine what's next : handling the file upload from the server, saving the file, displaying it if necessary, ....
Make sure you style the input element properly, taking into accound it's size (200px X 200px in my example).
Going further beyond
You can even set you input's opacity to 0 (zero) and put an image bellow or any visuel are text message saying : "Drag and drop file here to upload it" ....
Note :
- This works well in Chrome but not in my version of Firefox (3.6.13) which actaully tries to open the file you drop onto the page.
- HTML5 brings an implementation of drag-and-drop you can test here assuming you have the rigth browser (you can see your browser's HTML5 support here : http://html5test.com).
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
. Follow any responses to this post through RSS. You can leave a response, or trackback from your own site.
Inscription à :
Publier les commentaires (Atom)
mardi 9 septembre 2014 à 05:46:00 UTC−7
Thanks for the above post. I did the thing which is explained by you so many times but its not done. I don't know what is the problem? but I have the problem.
eSignature