Skip to content

Instantly share code, notes, and snippets.

@plugnburn
Forked from 140bytes/LICENSE.txt
Last active December 21, 2015 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plugnburn/6365797 to your computer and use it in GitHub Desktop.
Save plugnburn/6365797 to your computer and use it in GitHub Desktop.
Downloader.

Downloader

A function to force downloading any URL in modern browsers. 102 bytes.

Usage

download(url,optional_filename)

E.g.

download("https://gist.github.com/","gist_index.html")

Note: this function takes advantage of HTML5 "download" anchor attribute so for now it works only in decent&recent engines: WebKit, Blink and latest Gecko.

function(u,n){with(document.createElement("a"))href=u,download=n||u,dispatchEvent(new Event("click"))}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2013 plugnburn
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "download",
"description": "Force downloading of any URL in JS",
"keywords": [
"HTML5",
"download",
"force",
"anchor",
"spoof"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment