Skip to content

Instantly share code, notes, and snippets.

@ophentis
Created December 29, 2014 06:17
Show Gist options
  • Save ophentis/f7bc62c98c82b502788b to your computer and use it in GitHub Desktop.
Save ophentis/f7bc62c98c82b502788b to your computer and use it in GitHub Desktop.
download file from data uri in browsers
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