angular - 使用 window.open(...) 时带有 Angular 的浏览器选项卡标题
问题描述
在后面的代码中,我打开一个新的浏览器选项卡(窗口),其中包含 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>');
解决方案
您是否看过这篇文章如何使用 window.open() 显示窗口标题??
社区建议有几种方法可以实现这一目标
推荐阅读
- php - CakePHP 4 - 如何更改属性 - 实体中的字段映射?
- python - 为什么我的子图只绘制到最后一个斧头?
- angular - 带有笑话的角度8单元测试,用于http post catchError
- recursion - 如何对 Teradata 中的不同值进行递归
- python - 如何广播列表列表的总和?
- python-3.x - 将字典中键的值作为参数传递
- arrays - 使用字典作为 SwiftUI 的输入时显示视图列表的问题
- java - 将图像保存到 SharedPreferences
- node.js - mongoose.find() - 为什么嵌套数组返回为 [Object]
- python - 删除相似列数值匹配熊猫