Created
May 20, 2019 20:27
-
-
Save csandman/2f9b526e4a220d1f8a46fa81166a54cc to your computer and use it in GitHub Desktop.
JS Download Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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