Skip to content
索引

get请求下载文件

window.open打开新窗口

js
 window.location.href = `${window.BASE_URL}/yxyd/fa/downLoadYhDbFa`;
 window.location.href = `${window.BASE_URL}/yxyd/fa/downLoadYhDbFa`;

window.location.href不打开新窗口

js
 window.location.href = `${window.BASE_URL}/yxyd/fa/downLoadYhDbFa`;
 window.location.href = `${window.BASE_URL}/yxyd/fa/downLoadYhDbFa`;

使用iframe

js
 let iframe = document.createElement("iframe");
      iframe.style.display = "none"; // 防止影响页面
      iframe.style.height = 0; // 防止影响页面
      iframe.src = `${window.BASE_URL}/yxyd/fa/downLoadYhDbFa`; //下载url
      document.body.appendChild(iframe); // 这一行必须,iframe挂在到dom树上才会发请求
      setTimeout(() => {
        document.body.removeChild(iframe);
      }, 1500);
 let iframe = document.createElement("iframe");
      iframe.style.display = "none"; // 防止影响页面
      iframe.style.height = 0; // 防止影响页面
      iframe.src = `${window.BASE_URL}/yxyd/fa/downLoadYhDbFa`; //下载url
      document.body.appendChild(iframe); // 这一行必须,iframe挂在到dom树上才会发请求
      setTimeout(() => {
        document.body.removeChild(iframe);
      }, 1500);

Released under the MIT License.