Jeremy Stein - Brain

« »

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=""/>
<iframe id="file_download2" width="0" height="0" scrolling="no" frameborder="0" src=""/>
<iframe id="file_download3" width="0" height="0" scrolling="no" frameborder="0" src=""/>

Or here’s a fun little page that demonstrates the technique with Javascript:

    <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;
      <input type="checkbox" name="file1" value=""/><br/>
      <input type="checkbox" name="file2" value=""/><br/>
      <input type="checkbox" name="file3" value=""/><br/>
      <input type="button" onclick="download(this.form)" value="Download"/>
    <div id="iframe_holder"/>

February 29, 2008 3 Comments.


  1. 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.

  2. 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.

  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Why ask?

« »