Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save JavaScript-Packer/fd5a35fcf93fefab3a52 to your computer and use it in GitHub Desktop.

Select an option

Save JavaScript-Packer/fd5a35fcf93fefab3a52 to your computer and use it in GitHub Desktop.
Turn a string into a downloadable blob link to click on for download.
//create blob link for downloading data
var name = "YourFile.txt", data = "THIS IS JUST A TEST", d = "download", $ = "setAttribute", _ = document, r = new Blob([ data ], {
"type": "text/plain;charset=utf8;"
}), e = _.createElement("a");
void 0 !== e[d] ? (e[$]("href", window.URL.createObjectURL(r)), e[$](d, name)) : e[$]("href", "http://www.whak.com"),
e.innerHTML = "Download", _.body.appendChild(e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment