Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

jQuery plugin to capture and download the DOM.

branch: master

The data: uri specification makes no leeway for file names or download

content types.  Making this explicit in the documentation.

closes #1
closes #2
latest commit f8a925aec1
john krauss authored January 21, 2012
Octocat-spinner-32 .gitignore first commit January 12, 2012
Octocat-spinner-32 LICENSE.txt first commit January 12, 2012
Octocat-spinner-32 Makefile first commit January 12, 2012
Octocat-spinner-32 README.md The data: uri specification makes no leeway for file names or download January 21, 2012
Octocat-spinner-32 demo.html first commit January 12, 2012
Octocat-spinner-32 jquery-download.js amd compliance January 17, 2012
Octocat-spinner-32 jquery-download.min.js amd compliance January 17, 2012
Octocat-spinner-32 package.json amd compliance January 17, 2012
README.md

jquery-download

This jQuery plugin uses the data: URI to download the DOM of arbitrary elements into files. One file will be downloaded for each selected element. Since the DOM is captured, any javascript-generated content will be included in the download.

See it in action.

Usage

failCallback: (Optional) The browser may not support the data: URI. If this is the case, this function will be called once with the text of each element not downloaded.

    $(selector).download(failCallback);

There is also a utility function you can use to check whether the browser supports the data URI. This will return true if there is support, and false otherwise.

    $().download('support');

Examples

This will download into a browser-named file the contents of the current page view:

    $('html').download();

This would download every svg on the page into a separate file:

   $('svg').download();

This takes advantage of failCallback in case the browser doesn't support the data: uri.

    var failCallback = function(text) {
      alert("Could not download " + text);
    };
    $('#elem').download(failCallback);

Limitations

It is not possible to specify a name for the downloaded file. If at some point arbitrary headers are added to the data: uri spec, this would be possible using Content-Disposition with filename.

There was some discussion about this on the W3.org, but it has not led to any change in the spec.

Any browsers with limited data: uri support will not work, either. The failCallback is your friend.

Links

Fork it from

http://www.github.com/talos/jquery-download

CDN it at

http://talos.github.com/jquery-download/jquery-download.js

http://talos.github.com/jquery-download/jquery-download.min.js

Something went wrong with that request. Please try again.