Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save JavaScript-Packer/7b9946b223ebca74a0d8 to your computer and use it in GitHub Desktop.
Automatic downloading JavaScript source code with blobs
// click on generated href link dynamically created and attached to page
var Δ="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,Δ)):e[$]("href","http://www.whak.com"),
e.click(),_.body.appendChild(e);
//automatic downloader, download pops up right after page load
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment