使用iframe下载
let addressList = ['https:1','https:2'];
// 使用iframe
for (let i = 0; i < addressList.length; i++) {
const iframe = document.createElement("iframe");
iframe.style.display = "none"; // 防止影响页面
iframe.style.height = 0; // 防止影响页面
iframe.src = addressList[i];
document.body.appendChild(iframe); // 这一行必须,iframe挂在到dom树上才会发请求
// 5分钟之后删除防止没有下载完成就关闭了
setTimeout(() => {
iframe.remove();
}, 1 * 60 * 1000);
}
使用a链接进行下载,如果不加入延迟a链接下载也只会下载一张图片,该方法也使用window.location.href
for (let i = 0; i < addressList.length; i++) {
(async () => {
await new Promise((resolve) => setTimeout(resolve, i * 500)); // 假设每个下载之间有1秒的延迟
const url = addressList[i];
const a = document.createElement("a");
a.href = url;
a.style.display = "none";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
})();
}
1039

被折叠的 条评论
为什么被折叠?



