Created
February 12, 2011 05:05
-
-
Save yukioc/823536 to your computer and use it in GitHub Desktop.
HTML drag and drop sample
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
| <html> | |
| <body> | |
| <pre id="view" style="border:1px solid gray"> | |
| drag and drop file(s) here. | |
| </pre> | |
| <script language="JavaScript"> | |
| var view=document.getElementById('view'); | |
| function dragenter(evt) { | |
| evt.stopPropagation(); | |
| evt.preventDefault(); | |
| } | |
| function dragover(evt) { | |
| evt.stopPropagation(); | |
| evt.preventDefault(); | |
| } | |
| function drop(evt) { | |
| evt.stopPropagation(); | |
| evt.preventDefault(); | |
| var files=evt.dataTransfer.files; | |
| for (var i=0,f;f=files[i];i++){ | |
| view.innerHTML += "\n" + f.name; | |
| } | |
| } | |
| view.addEventListener('dragenter', dragenter, false); | |
| view.addEventListener('dragover', dragover, false); | |
| view.addEventListener('drop', drop, true); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment