Skip to content

Instantly share code, notes, and snippets.

@talcual
Forked from jmcarp/forceDownload.js
Created December 1, 2021 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talcual/1d8ecd2dfb08913a10b24e96e2797da1 to your computer and use it in GitHub Desktop.
Save talcual/1d8ecd2dfb08913a10b24e96e2797da1 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