我的代码是从 pdf 文件创建 blob url 并在新窗口中打开该文件。这在 Chrome、Firefox、IE 等中运行良好,但是当我尝试在 Safari blob url 更改中重新刷新页面时,显然通过该地址我什么都没有。你能帮助我吗?
我的代码如下所示:
getFile(url).then(({fileBlob}) => {
const pdfBlob = new Blob([fileBlob], {type: 'application/pdf'});
if (window.navigator?.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(pdfBlob);
} else {
const blobUrl = (URL || webkitURL).createObjectURL(pdfBlob);
const windowRef = window.open(blobUrl);
let currentWindowLifeTime = 0;
const timerId = setInterval(() => {
currentWindowLifeTime += 10000;
if (currentWindowLifeTime >= 600000|| windowRef?.closed) {
clearInterval(timerId);
(URL || webkitURL).revokeObjectURL(blobUrl);
}
}, 10000);
}
});