Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Created January 27, 2016 00:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crobinson42/b7c7981d8db355a5a570 to your computer and use it in GitHub Desktop.
Save crobinson42/b7c7981d8db355a5a570 to your computer and use it in GitHub Desktop.
/*
This will create a file and trigger a download for the user.
*/
var a = window.document.createElement('a');
a.href = window.URL.createObjectURL(new Blob(['This is the text in the file..'], {type: 'text/html'}));
a.download = 'filename_test.html';
// Append anchor to body.
document.body.appendChild(a)
a.click();
// Remove anchor from body
document.body.removeChild(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment