Skip to content

Instantly share code, notes, and snippets.

@evilpie
Created August 5, 2010 01:59
Show Gist options
  • Save evilpie/509105 to your computer and use it in GitHub Desktop.
Save evilpie/509105 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Drag and Drop Download</title>
<script>
window.addEventListener('DOMContentLoaded', function () {
var downloadLink = document.getElementById('download');
/*
Add an event handler to the link, wich fires when you drag it
*/
downloadLink.addEventListener('dragstart', function (event) {
/*
DownloadURL indicates Chrome that this file/link should be a download file
The actuall data is like <mimetype>:<filename>:<url>
This was proposed here: http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-August/022118.html
*/
event.dataTransfer.setData('DownloadURL', 'application/pdf:ECMA-262.pdf:http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf');
});
});
</script>
</head>
<body>
<a id="download" href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">ECMA 262</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment