我在使用ios Safari时遇到一个非常奇怪的问题。
我正在尝试在浏览器中保存png。如果我在当前选项卡中打开png,它会起作用,但是当我尝试在新选项卡中打开它时,它什么也不会做。我真的不明白是什么问题
这是我的代码:
downloadFile(filename, blob, type) {
/* Evergreen Browsers */
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', filename);
console.log(url, filename);
link.setAttribute('target', '_blank'); //If i remove this line it opens the png file otherwise it doesnt do any thing, notice that i only have this problem in ios/safari with pngs, it works fine for other types like csv
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
canvas.toBlob(function (blob) {
downloadFile(
'a.png,
blob,
'image/png;',
);
});