Skip to content

Instantly share code, notes, and snippets.

@NaClYen
Created June 28, 2022 09:49
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 NaClYen/20669b8e9035b37b3434e61e89f7ffea to your computer and use it in GitHub Desktop.
Save NaClYen/20669b8e9035b37b3434e61e89f7ffea to your computer and use it in GitHub Desktop.
auto download file in web
function download(source) {
const fileName = source.split("/").pop();
let el = document.createElement("a");
el.setAttribute("href", source);
el.setAttribute("download", fileName);
document.body.appendChild(el);
el.click();
el.remove();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment