Skip to content

Instantly share code, notes, and snippets.

@lincerely
Last active September 1, 2016 10:07
Show Gist options
  • Save lincerely/b7be27aea493f966d33f7332604bf9e8 to your computer and use it in GitHub Desktop.
Save lincerely/b7be27aea493f966d33f7332604bf9e8 to your computer and use it in GitHub Desktop.
download file from link with "a" 's download tag
<head>
<meta charset="UTF-8">
<title>Download from link</title>
</head>
<body>
<h1>Please use Chrome or Opera</h1>
<h2>cross origin download is not allow in Firefox,<br> so it will open the file in your broswer.</h2>
<input id="link" type="text" />
<a id="button" download>Download</a>
<script>
var link = document.getElementById('link');
var button = document.getElementById('button');
link.onchange = function(){
button.href = link.value;
console.log('link changes to '+link.value);
}
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment