Created
September 23, 2014 19:30
-
-
Save jeremyckahn/2e0f2d7f9e2a47c2ab20 to your computer and use it in GitHub Desktop.
downloadTextAsFile.js
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
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