如何在IE中一次下载多个文件 [英] How to download multiple files in one shot in IE

查看:140
本文介绍了如何在IE中一次下载多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想点击jsp中的按钮下载多个文件。

我在js中使用以下代码来调用一个servlet两次。

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);

在xyz.jsp中我调用servlet从路径下载文件并将其发送到浏览器。

问题是它正在运行safari,firefox但不在IE中。

我们无法用IE下载多个文件?

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?

推荐答案

我使用以下代码在IE和Chrome中下载多个文件

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);
}

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

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!

这篇关于如何在IE中一次下载多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆