【发布时间】:2021-12-14 06:52:15
【问题描述】:
在后面的代码中,我打开一个新的浏览器选项卡(窗口),其中包含 PDF 作为内容,来自服务器的 blob 数据。 它可以工作,文档会打开一个新选项卡,但浏览器选项卡的标题是一些十六进制代码。 我可以动态更改此浏览器选项卡标题吗?比如“文档”?
这是我使用的代码(抱歉,由于数据来自服务器,因此无法进行 StackBlitz 示例):
const file = new Blob([data], {type:'application/pdf'});
const fileURL = URL.createObjectURL(file);
window.open(fileURL, '_blank');
在这里,我的浏览器标签看起来像这样:
解决方案(适用于 Chrome 和 Edge):
var w = window.open(fileURL, '_blank');
setTimeout(function(){ w.document.title = 'My title'; }, 500);
其他解决方案(适用于 Chrome、FF 和 Edge):
var w = window.open(fileURL, '_blank');
w.document.write('<html><head><title>My title</title></head><body height="100%" width="100%"><iframe src="' + fileURL+ '" height="100%" width="100%"></iframe></body></html>');
【问题讨论】:
标签: angular typescript web