JS文件下载页面跳转出现空白页解决办法

JS文件下载页面跳转出现空白页解决办法

原因

文件下载出现空白页或页面跳转,是因为直接用文件地址跳转window.open或者location.href这种方式会有页面跳转的情况出现。 如果用iframe来做就可以解决这个问题

实例

//传入参数src为文件地址

function download (src) {

var download_file= {}

if (typeof(download_file.iframe) == "undefined") {

var iframe = document.createElement("iframe");

download_file.iframe = iframe;

document.body.appendChild(download_file.iframe);

}

download_file.iframe.src = src

download_file.iframe.style.display = "none";

},

function downloadFile() {

try{

var urlFile="http://localhost/File/test.xls";

var elemIF = document.createElement("iframe");

elemIF.src = urlFile;

elemIF.style.display = "none";

document.body.appendChild(elemIF);

}catch(e){

}

}

相关推荐

best365足球 pkpm 中的轴线怎么删除?

pkpm 中的轴线怎么删除?

📅 10-18 👁️ 2186
beat365平台正版 为什么不能在outlook中删除联系人