iframe標簽方法下載:
var downloadFileUrl = "http://localhost:3000" var elemIF = document.createElement("iframe"); elemIF.src = downloadFileUrl; elemIF.style.display = "none"; document.body.appendChild(elemIF);
a標簽方法下載:
const a = document.createElement('a'); // 創建a標簽 a.setAttribute('download', '');// download屬性 a.setAttribute('href', downloadFileUrl);// href鏈接
a.click();// 自執行點擊事件
上述兩種方式僅僅就是發送一個請求,主要依賴后端的支持;對不需要精確知道文件下載的狀態,上面方式就能滿足下載;