Last active
December 17, 2015 08:29
-
-
Save danbrianwhite/75a93a0af691a597247a to your computer and use it in GitHub Desktop.
Save a string of text as a file with HTML5 (Chrome)
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 saveTextAsFile(filename, text) | |
{ | |
var textToWrite = text; | |
var textFileAsBlob = new Blob([textToWrite], {type:'text/html'}); | |
var fileNameToSaveAs = filename; | |
var downloadLink = document.createElement("a"); | |
downloadLink.href = window.URL.createObjectURL(textFileAsBlob); | |
downloadLink.download = fileNameToSaveAs; | |
downloadLink.click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment