首页 > 其他 > 详细

多个文件下载

时间:2021-09-12 01:42:40      阅读:34      评论:0      收藏:0      [点我收藏+]
        this.file_url = ["http://123", "http://1234", "http://1235"];//文件地址
        // a链接版本--下载文件
        for (let i = 0; i < this.file_url.length; i++) {
          let url = window.URL.createObjectURL(new Blob([this.file_url[i]]));
          let link = document.createElement("a");
          link.style.display = "none";
          link.href = url;
          let fileName = this.file_url[i].substring(
            this.file_url[i].lastIndexOf("/") + 1,
            this.file_url[i].length
          );
          link.setAttribute("download", fileName);
          document.body.appendChild(link);
          link.click();
        }

        // iframe版本--下载文件
        for (let i = 0; i < this.file_url.length; i++) {
          const iframe = document.createElement("iframe");
          iframe.style.display = "none"; // 防止影响页面
          iframe.style.height = 0; // 防止影响页面
          iframe.src = this.file_url[i]; // url自己进行指定
          document.body.appendChild(iframe); // 这一行必须,iframe挂在到dom树上才会发请求
          setTimeout(() => {
            iframe.remove(); // 5分钟之后删除
          }, 5 * 60 * 1000);
       }

多个文件下载

原文:https://www.cnblogs.com/33shan/p/15250384.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!