function downloadImage(base64Url) {
let imgUrl = base64Url;
if (window.navigator.msSaveOrOpenBlob) {//兼容IE浏览器的写法
let imageStr = atob(imgUrl.split(",")[1]);
let n = imageStr.length;
let u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = imageStr.charCodeAt(n);
}
let blob = new Blob([u8arr]);
window.navigator.msSaveOrOpenBlob(blob, "chart-download" + "." + "png");
} else {//非IE浏览器
let a = document.createElement("a");
a.href = imgUrl;
a.setAttribute("download", "chart-download");
a.click();
}
}
标签:imageStr,海报,msSaveOrOpenBlob,base64,html2canvas,let,download,u8arr,imgUrl
From: https://www.cnblogs.com/c0lmd0wn/p/17853550.html