原因
文件下载出现空白页或页面跳转,是因为直接用文件地址跳转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){
}
}