如何在IE中一次下载多个文件

use*_*194 8 javascript internet-explorer

我想点击jsp中的按钮下载多个文件.
我在js中使用以下代码来调用一个servlet两次.

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);
Run Code Online (Sandbox Code Playgroud)

在xyz.jsp中,我调用servlet,它从路径下载文件并在浏览器上发送.
问题是它正在运行safari,firefox但不在IE中.
我们无法用IE下载多个文件?

Eri*_*Law 5

根据设计,非用户启动的文件下载在 IE 中被阻止。这本质上意味着,用户单击一次就可以下载多个文件。


Dar*_*ren 5

我使用以下代码在 IE 和 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);
}
Run Code Online (Sandbox Code Playgroud)

您将 URL 数组传递给 downloadFiles() 函数,该函数将为每个 URL 调用 downloadFile() ,并且之间有短暂的延迟。延迟似乎是让它发挥作用的关键!