Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery download a zipfile from a button?

Tags:

jquery

button

zip

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.

like image 741
FFish Avatar asked May 20 '10 23:05

FFish


1 Answers

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.

like image 185
bobince Avatar answered Nov 12 '22 04:11

bobince