Skip to content

Instantly share code, notes, and snippets.

@LarryKHite
Forked from jmcarp/forceDownload.js
Created October 27, 2018 12:58
Show Gist options
  • Save LarryKHite/fa1c083ee5df4738b79091ebbabaf3d0 to your computer and use it in GitHub Desktop.
Save LarryKHite/fa1c083ee5df4738b79091ebbabaf3d0 to your computer and use it in GitHub Desktop.
Forcing a file download in JavaScript
function forceDownload(href) {
var anchor = document.createElement('a');
anchor.href = href;
anchor.download = href;
document.body.appendChild(anchor);
anchor.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment