Skip to content

Instantly share code, notes, and snippets.

@luiswolff
Created March 14, 2022 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luiswolff/ddd3015b19e9d3ec23f0a94bfcf37e80 to your computer and use it in GitHub Desktop.
Save luiswolff/ddd3015b19e9d3ec23f0a94bfcf37e80 to your computer and use it in GitHub Desktop.
// 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