Automatic Download Function Through Javascript

1 · Xiang Yu · Nov. 28, 2021, 1:31 p.m.
js实现点击浏览器自动下载记录一下用纯js实现各种浏览器自动下载的功能。兼容IE。123456789101112131415161718192021222324252627282930313233343536373839404142downloadDocument("YOUR DOCUMENT");function downloadDocument(pdfType) { // your defination of file url and file name let fileUrl = documentInfo[pdfType]["url"]; let fileName = `${documentInfo[pdfType]["name"]}.pdf`; const oReq = new XMLHttpRequest(); oReq.open("GET", fileUrl, true); oReq.responseType = "blob"; oReq.onload = function () { const fileBlob = new Blob([oReq.res...