Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download multiple files in one shot in IE

I want to download multiple files on click of a button in jsp.
I am using the following code in the js to call one servlet twice.

var iframe = document.createElement("iframe");
iframe.width = iframe.height = iframe.frameBorder = 0;
iframe.scrolling = "no";
iframe.src = "/xyz.jsp?prodId=p10245";
document.getElementById("iframe_holder").appendChild(iframe);

var iframe2 = document.createElement("iframe");
iframe2.width = iframe2.height = iframe2.frameBorder = 0;
iframe2.scrolling = "no";
iframe2.src = "/xyz.jsp?prodId=p10243";
document.getElementById("iframe_holder").appendChild(iframe2);

In xyz.jsp i am calling the servlet which downloads the file from a path and send it on the browser.
Issue is that it is working safari,firefox but not in IE.
We cannot download multiple files with IE?

like image 862
user666194 Avatar asked Mar 18 '11 14:03

user666194


People also ask

How do I download multiple files at once?

Hold CTRL and click on the files you want to download. Once you have selected the files you want, right click on the last file you selected and select download.

Is there a way to queue downloads?

Through Right-Click Context Menu To add all files to the download queue, right-click anywhere on the screen, hover the cursor over DownThemAll!, and select DownThemAll!. Then, select the types of files and choose Download. In the same way, you can download files from all the tabs together.


2 Answers

By design, non-user-initiated file downloads are blocked in IE. That inherently means that it should not be possible to download more than one file as the result of a single user-click.

like image 181
EricLaw Avatar answered Nov 03 '22 23:11

EricLaw


I've used the following code to download multiple files in IE and Chrome

function downloadFile(url)
{
    var iframe = document.createElement("iframe");
    iframe.src = url;
    iframe.style.display = "none";
    document.body.appendChild(iframe);
}

function downloadFiles(urls)
{
    downloadFile(urls[0]);
    if (urls.length > 1)
        window.setTimeout(function () { downloadFiles(urls.slice(1)) }, 1000);
}

You pass an array of URLs to the downloadFiles() function, which will call downloadFile() for each with a short delay between. The delay seems to be the key to getting it to work!

like image 38
Darren Avatar answered Nov 04 '22 01:11

Darren