【问题标题】:Browser tab title with Angular when using window.open(...)使用 window.open(...) 时带有 Angular 的浏览器选项卡标题
【发布时间】: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


    【解决方案1】:

    你看过这个帖子how to show window title using window.open()?吗?

    社区建议有几种实现此目的的方法

    【讨论】:

    • 谢谢,我已经找到了解决方案。
    猜你喜欢
    • 2020-06-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多