Created
June 21, 2016 08:44
-
-
Save AlexKotel/5ce310cb93a52ffdbe51c3a24309a0be to your computer and use it in GitHub Desktop.
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 writeFile(content, name) { | |
name = name || 'filename.txt'; | |
var a = document.createElement('a'); | |
a.hidden = ''; | |
a.href = 'data:text/json,' + encodeURIComponent(content); | |
a.download = name; | |
a.textContent = 'Download file '+name+'!'; | |
console.log(a); | |
document.body.appendChild(a); | |
} | |
writeFile('Hello world!', 'test'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment