Skip to content

Instantly share code, notes, and snippets.

@csandman
Created May 20, 2019 20:27
Show Gist options
  • Save csandman/2f9b526e4a220d1f8a46fa81166a54cc to your computer and use it in GitHub Desktop.
Save csandman/2f9b526e4a220d1f8a46fa81166a54cc to your computer and use it in GitHub Desktop.
JS Download Function
function download(filename, filepath) {
let element = document.createElement('a');
element.setAttribute('href', filepath);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// Start file download.
download("hello.txt","This is the content of my file :)");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment