window.open 循环下载多个文件会打开新页签问题解决
批量下载文件,循环使用window.open(url) 的方式会打开新页签,参考了一位大侠的文章,使用iframe可以的: https://blog.csdn.net/nanke_yh/article/details/125145717
如下:
如下:
fileList.forEach(file => { //同时下载多个文件,使用iframe下载,因为window.open或者a都会被拦截 const url = file.url + "?attname=" + file.name; let iframe = document.createElement('iframe'); iframe.id = file.id; iframe.style.display = "none"; document.body.appendChild(iframe); iframe.src = url; })