Created
December 26, 2019 08:26
-
-
Save hoodwink73/58ea33bc100fcc74c0759938b102fc33 to your computer and use it in GitHub Desktop.
Create downloadable files on the client side
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
// https://stackoverflow.com/a/18197341/1481710 | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment