我写了这个 JS [attrDownloadIE.js]
// author: Carlos Machado
// version: 0.1
// year: 2015
//
var f_name = "";
var f_ref = "";
function reqListener() {
if(f_name == "") {f_name = f_ref;}
var blobObject = this.response;
window.navigator.msSaveBlob(blobObject, f_name);
}
function myDownload(evt) {
f_name = this.getAttribute("download");
f_ref = this.getAttribute("href");
evt.preventDefault();
var oReq1 = new XMLHttpRequest();
oReq1.addEventListener("load",reqListener, false);
oReq1.open("get", this, true);
oReq1.responseType = 'blob';
oReq1.send();
}
document.addEventListener(
"load",
function(event){
var isIE = /*@cc_on!@*/false || !!document.documentMode;
if(isIE) {
var items = document.querySelectorAll('a[download], area[download]');
for(var i = 0; i < items.length; i++) {
items[i].addEventListener('click', myDownload, false);
}
}
}
);