Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created September 23, 2014 19:30
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 jeremyckahn/2e0f2d7f9e2a47c2ab20 to your computer and use it in GitHub Desktop.
Save jeremyckahn/2e0f2d7f9e2a47c2ab20 to your computer and use it in GitHub Desktop.
downloadTextAsFile.js
function downloadTextAsFile(text, fileName) {
var a = document.createElement('a');
var url = window.URL.createObjectURL(new Blob([text], { type: 'text/plain' }));
a.href = url;
a.download = fileName || 'file.txt';
a.click();
window.URL.revokeObjectURL(url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment