In general, our JS file download is located to the back-end interface using window.location.href, the back-end generated file is returned, and the browser automatically downloads it. This method is the simplest, but it cannot obtain the notification of successful download. When large files are generated and downloaded, the time is too long, and users may repeatedly click the download, causing a burden on the server. At the same time, solve the problem that the + a tag base64url is too long to be downloaded triggered by different browsers.

Load = function() {var index = layer.load(1, {shade: [0.25, '#333'] //0.1 opacity white background}); } disload = function() {layer.close(index);} disload = function() {layer.close(index); } getDownload = function(url) {load(); var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); Xhr. responseType = "blob"; xhr.onload = function() { if (this.status === 200) { var blob = this.response; if (navigator.msSaveBlob == null) { var a = document.createElement('a'); var headerName = xhr.getResponseHeader("Content-disposition"); var fileName = decodeURIComponent(headerName).substring(20); a.download = fileName; a.href = URL.createObjectURL(blob); $("body").append(a); a.click(); URL.revokeObjectURL(a.href); $(a).remove(); } else { navigator.msSaveBlob(blob, fileName); } } disload(); }; xhr.send() };Copy the code