Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created April 30, 2015 18:45
Show Gist options
  • Select an option

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

Select an option

Save JavaScript-Packer/591d504b38dc5be6d7eb to your computer and use it in GitHub Desktop.
Make a JavaScript source code into a download link using blobs. Click link to download.
//make a javascript source code downloadable by blob
var name="script.js",data="alert('THIS IS 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