前端下載靜態文件,顯示進度


function blobStart(url,filekey,name,extension){
var x=new XMLHttpRequest();
x.open("GET", url, true);
x.responseType = 'blob';
x.send();

x.onload=function(e){

let url=URL.createObjectURL( x.response);
var a = document.createElement("a");
a.href = url;
a.download = name;
a.click();
// postData();
window.URL.revokeObjectURL(a.href);
}
x.addEventListener("progress", function(event) {
if (event.lengthComputable) {
var percentComplete = event.loaded / event.total * 100;
 
console.log(percentComplete);
// ...
 
} else {
// Unable to compute progress information since the total size is unknown
}
}, false);
x.onerror = function(){
console.log("文件下載失敗");
 
}
 
 
 
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM