IE11 Blob對象報錯 關於Blob文檔下載----瀏覽器兼容性問題

此方案是度娘查詢到的,忘了是哪個網址了

if( window.navigator && window.navigator.msSavaOrOpenBlob ) {

navigator.msSavaBlob(new Blob([req.data],name));

}else {

let url = window.URL.createObjectURL(new Blob([req.data]));

let link =document.createElement('a');

link.style.display = 'none';

link.href = url;

link.setAttribute('download',name);

document.body.appendchild(link);

link.click();

URL.revokeObjectURL(url);

document.body.removeChild(link);

}

其中name是下載文件的名稱,即下載後文件名稱;

req爲接口返回的文件流數據;

msSavaOrOpenBlob 是指允許用戶在客戶端上保存及打開文件

URL.createObjectURL() 創建一個DOMString,這個URL表示指定的File對象或Blob對象。其返回一段帶有hash的url,並且儲存在內存中,直到document觸發unload方法,或者調用revokeObjectURL來釋放內存。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章