const u = navigator.userAgent;
let isIos = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if(isIos) {
const b64File = this.dataURL;
const contentType = b64File.substring(5, b64File.indexOf(';base64')) // 截取文件类型
const b64Data = b64File.substring(b64File.indexOf(',') + 1) // 获得文件头外的数据
const byteCharacters = atob(b64Data)
const byteNumbers = new Array(byteCharacters.length)
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i)
}
const byteArray = new Uint8Array(byteNumbers)
const blob = new Blob([byteArray], {type: contentType})
const u = window.URL.createObjectURL(blob) // 获得的链接
location.href = u;
} else {
const hideDownload = document.createElement('a');
hideDownload.href = this.dataURL;
hideDownload.download = '快照';
hideDownload.target = '_blank';
hideDownload.click();
hideDownload.remove();
}
|