jQuery download a zipfile from a button?

button, jquery, zip

Solution

Use a plain:

<a href="http://localhost/admin/zip/002140.zip" id="button-download">download zipfile</a>

link. Then it'll work fine (“bullet proof” even) without JavaScript available. It also offers more of the traditional affordances users might expect from a download link, such as right-click-save-as, or drag-and-drop.

You can of course use CSS to make it look like a button instead of a link. But what it actually is, is a link. So that's how it should be marked up.

Problem

Quite embarrassing how much time I spend trying to get to download a zipfile from a button.... ``` <button type='button' id='button-download'>download zipfile</button> $("#button-download").live("click", function() { $.get("http://localhost/admin/zip/002140.zip"); // doesn't work? }) ``` I need something bullet proof here, that's why I ask here, thanks.

Original source