[英]How to download multiple files with window.open()?
I am trying to download multiple files at once.我正在尝试一次下载多个文件。 At first I use
window.location = url
but now it doesn't seem to work.起初我使用
window.location = url
但现在它似乎不起作用。
I've changed it to window.open(url, "_blank")
and it only downloads the first one:我已将其更改为
window.open(url, "_blank")
并且它只下载第一个:
window.open("/host/Controller/DownloadDasFiles?paramId=204");
window.open("/host/Controller/DownloadDasFiles?paramId=205");
window.open("/host/Controller/DownloadDasFiles?paramId=206");
public FileResult DownloadDasFiles(int paramId)
{
var dasControl = UnityConfig.container.Resolve<IDasControlService>();
var filename = dasControl.GetDasFileToDownload(paramId);
return File(filename, "application/octet-stream", Path.GetFileName(filename));
}
In my real case I do this after AJAX success in a javascript loop, but this code should work, shouldn't it?在我的真实情况下,我在 javascript 循环中 AJAX 成功后执行此操作,但是此代码应该可以工作,不是吗?
This may help.这可能会有所帮助。 It will open all 3 windows at same time.
它将同时打开所有 3 个窗口。
let test = [204, 205, 206];
let downLoadFileBaseUrl = '/host/Controller/DownloadDasFiles?paramId='
test.forEach(element => {
let file = `${downLoadFileBaseUrl}+${element}`;
window.open(file, '_blank', 'File :' + element + ',scrollbars=1,menubar=0,resizable=1,width=850,height=500');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.