Created
December 29, 2014 06:17
-
-
Save ophentis/f7bc62c98c82b502788b to your computer and use it in GitHub Desktop.
download file from data uri in browsers
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(content,filename) { | |
downloadURI('data:application/javascript;charset=UTF-8,' + encodeURIComponent(content), filename); | |
} | |
function downloadURI(uri, name) { | |
var link = document.createElement('a') | |
link.download = name | |
link.href = uri | |
$(link).appendTo('body') //document.body.appendChild(link) | |
link.click() | |
$(link).remove() //document.body.removeChild(link) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment