Created
September 29, 2014 16:44
-
-
Save danallison/3ec9d5314788b337b682 to your computer and use it in GitHub Desktop.
download string as text file
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 downloadString(text, fileType, fileName) { | |
var blob = new Blob([text], { type: fileType }); | |
var a = document.createElement('a'); | |
a.download = fileName; | |
a.href = URL.createObjectURL(blob); | |
a.dataset.downloadurl = [fileType, a.download, a.href].join(':'); | |
a.style.display = "none"; | |
document.body.appendChild(a); | |
a.click(); | |
document.body.removeChild(a); | |
setTimeout(function() { URL.revokeObjectURL(a.href); }, 1500); | |
} | |
// downloadString("a,b,c\n1,2,3", "text/csv", "myCSV.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow ty, I will have a look at it