Created
July 29, 2019 21:06
-
-
Save benhg/c071f421a02b2bb4fbef0d714efb863f to your computer and use it in GitHub Desktop.
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, text) { | |
var element = document.createElement('a'); | |
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | |
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