Created
March 16, 2021 13:48
-
-
Save userddssilva/087efa9e4f47a916ba46a68f4da2fcd3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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