我想在blob的createObjectURL中设置一个自定义文件名。现在,它展示的是这样的东西:
/bfe410-8d9c-4883-86c5-d76c50a24a1d
const data = window.URL.createObjectURL(newBlob);
const pdfWindow = window.open();
pdfWindow.location.href = data;
我不想下载这个文件(它的解决方案已经出现在StackOverflow上了),它应该在一个新的选项卡中打开。
发布于 2022-09-01 21:28:31
参考Set tab title on javascript window.open to show PDF file和Set title in the window popup的答案,我用以下解决方案进行了测试,这些解决方案在大多数浏览器上都能很好地工作。
const data = window.URL.createObjectURL(newBlob);
const pdfWindow = window.open();
pdfWindow.location.href = data;
fileTitle = "hello-world.pdf";
// Set the window title
newWindow.document.title = fileTitle;
// Make sure that the window is loaded
pdfWindow.onload = () => {
// And then add a timeout to guarentee the title is changed
setTimeout(() => {
newWindow.document.title = fileTitle;
}, 500)
}
https://stackoverflow.com/questions/69315731
复制相似问题