当我在Microsoft Edge中按网站上的下载按钮时,出现“预期功能”错误。
download() {
this.element = document.getElementById("img") as HTMLElement;
let dataurl = this.element.innerHTML;
let myRegexp = /(?:^|\s)src=(.*?)(?:\s|$)/g;
let match = myRegexp.exec(dataurl);
let match1 = match[1].replace('"></div>', '');
this.ImageURL = match1;
let block = this.ImageURL.split(";");
let contentType = block[0].split(":")[1];
let realData = block[1].split(",")[1];
let file = this.dataURLtoFile(this.ImageURL, 'QRCode.png');
}
dataURLtoFile(dataurl, filename) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
var a = document.createElement("a");
document.body.appendChild(a);
var blob = new Blob([new File([u8arr], filename, { type: mime })], { type: 'mime' }),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = `QRCode.png`;
a.click();
setTimeout(function () {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 100);
return new File([u8arr], filename, { type: mime });
}
文件应下载:
这是错误:
[对象错误]:{描述:“预期功能”,消息:“功能 预期”,数字:-2146823286,堆栈:“ TypeError:预期功能 在n.prototype.dataURLtoFile (http://instacei.com/1.bb25259c0233e7528077.js:1:237067)在 n.prototype.download (http://instacei.com/1.bb25259c0233e7528077.js:1:236764)在匿名 功能(http://instacei.com/1.bb25259c0233e7528077.js:1:155143)在 handleEvent (http://instacei.com/main.1533bf301f026a959db3.js:1:117135)在 handleEvent (http://instacei.com/main.1533bf301f026a959db3.js:1:138938)在Lr (http://instacei.com/main.1533bf301f026a959db3.js:1:87225)在 匿名功能 (http://instacei.com/main.1533bf301f026a959db3.js:1:93361)在 匿名功能 (http://instacei.com/main.1533bf301f026a959db3.js:1:284082)在 e.prototype.invokeTask (http://instacei.com/polyfills.481858ef51fe27531859.js:1:7664)在 onInvokeTask (http://instacei.com/main.1533bf301f026a959db3.js:1:55627)“}