Jeremy Stein - Brain
« TrueCrypt Mac Traveler mode | Recursively expand compressed files » |
Download multiple files
To send multiple files to the web browser, embed the files in hidden iframes like this:
<iframe id="file_download1" width="0" height="0" scrolling="no" frameborder="0" src="file1.zip"/> <iframe id="file_download2" width="0" height="0" scrolling="no" frameborder="0" src="file2.zip"/> <iframe id="file_download3" width="0" height="0" scrolling="no" frameborder="0" src="file3.zip"/>
Or here’s a fun little page that demonstrates the technique with Javascript:
<html> <head> <script language="javascript"> function download(form) { for(var i=0; i<form.elements.length; i++) { var element = form.elements[i]; if (element.type == "checkbox") { if (element.checked) { var iframe = document.createElement("iframe"); iframe.width = iframe.height = iframe.frameBorder = 0; iframe.scrolling = "no"; iframe.src = element.value; document.getElementById("iframe_holder").appendChild(iframe); } } } } </script> </head> <body> <form> <input type="checkbox" name="file1" value="file1.zip"/>file1.zip<br/> <input type="checkbox" name="file2" value="file2.zip"/>file2.zip<br/> <input type="checkbox" name="file3" value="file3.zip"/>file3.zip<br/> <input type="button" onclick="download(this.form)" value="Download"/> </form> <div id="iframe_holder"/> </body> </html>
3 Comments
- Kenneth replied:
I tried the Javascript for Downloading Multiple Files but it does not work?
Any insight?
July 26th, 2011 at 3:25 am. Permalink.
- Jeremy replied:
I’m not sure why the JavaScript doesn’t work. But it should give you an idea of the approach you can take. Good luck!
July 26th, 2011 at 9:08 am. Permalink.
- Pradeep replied:
Super Cool…Though the exact snippet doesn’t work, I was able to plug in the relevant code and it works like a charm! Thanks..
September 29th, 2011 at 1:09 pm. Permalink.
« TrueCrypt Mac Traveler mode | Recursively expand compressed files » |
Leave a Reply