Created
April 23, 2015 12:25
-
-
Save formigone/c25191d203b66cd81a6c to your computer and use it in GitHub Desktop.
Save data from JavaScript to client
This file contains hidden or 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
// This snippet came from some website and is not original | |
function saveTextAsFile() | |
{ | |
var textToWrite = 'lorem ipsum'; | |
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'}); | |
var fileNameToSaveAs = 'html5-blob-to-file.txt' | |
var downloadLink = document.createElement('a'); | |
downloadLink.download = fileNameToSaveAs; | |
downloadLink.innerHTML = "Download File"; | |
// Firefox requires the link to be added to the DOM before it can be clicked. | |
downloadLink.href = window.URL.createObjectURL(textFileAsBlob); | |
downloadLink.style.display = "none"; | |
document.body.appendChild(downloadLink); | |
downloadLink.click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment