-
-
Save webkupas/cd3c8f65648d9e4d117ed6708f09b837 to your computer and use it in GitHub Desktop.
Save a text file locally with a filename, by triggering a download in JavaScript
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
| /* | |
| * Save a text file locally with a filename by triggering a download | |
| */ | |
| var text = "hello world", | |
| blob = new Blob([text], { type: 'text/plain' }), | |
| anchor = document.createElement('a'); | |
| anchor.download = "hello.txt"; | |
| anchor.href = (window.webkitURL || window.URL).createObjectURL(blob); | |
| anchor.dataset.downloadurl = ['text/plain', anchor.download, anchor.href].join(':'); | |
| anchor.click(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment