Created
March 14, 2022 16:46
-
-
Save luiswolff/ddd3015b19e9d3ec23f0a94bfcf37e80 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
// For more information see: https://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file | |
var pom = document.createElement('a'); | |
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent('hello world!')); | |
pom.setAttribute('download', 'test.txt'); | |
if (document.createEvent) { | |
var event = document.createEvent('MouseEvents'); | |
event.initEvent('click', true, true); | |
pom.dispatchEvent(event); | |
} | |
else { | |
pom.click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment