javascript - 从chrome中的父选项卡设置角度应用程序的标题
问题描述
我有一个应用程序,它在单击按钮时在新选项卡中打开另一个角度应用程序。我需要从父选项卡覆盖新选项卡的标题并设置一个值。下面的一些模拟代码
<!DOCTYPE html>
<html>
<head>
<title>New tab</title>
</head>
<body>
<div>
<input id="toolId" placeholder="ToolId" style="padding: 4px 0; width: 70px;" />
<button id="button">Launch</button>
</div>
<script>
window.onload = function () {
document.getElementById('button').addEventListener('click', () => {
var newWin = window.open('http://localhost:4200', "_blank");
// add a load listener to the window so that the title gets changed on page load
newWin.onload = function() {
newWin.document.title = 'New Title';
console.log('Loaded');
};
// newWin.document.title = 'New Title';
})
}
</script>
</body>
</html>
但是当我尝试这样做时,我总是看到角度应用程序设置的默认值,而不是上面代码设置的默认值。我在这里想念什么?是不是偶然被chrome屏蔽了,如果是的话,找不到任何相关的文档。
解决方案
您可以在文档中找到对此的解释:
<title> 的问题:
显而易见的方法是将组件的属性绑定到 HTML,如下所示:
<title>{{This_Does_Not_Work}}</title>
对不起,但这行不通。应用程序的根组件是标签中包含的元素。HTML <title> 在文档中,在正文之外,使得 Angular 数据绑定无法访问。您可以抓取浏览器文档对象并手动设置标题。这很脏,并且会破坏您有一天在浏览器之外运行应用程序的机会。
推荐阅读
- laravel - Laravel 多个工人运行两次工作
- swift - “ExpressibleByArrayLiteral”可以是通用的吗?
- vba - VBA:如何从文件夹中的所有 txt 文件中读取和复制特定字符串
- macos - ddd 在 macOS 上“无法打开显示”
- c# - GetMember() 可以为枚举返回一个空数组吗?
- java - HTTP2 请求示例使用 Jmeter4、Java 10 No Client ALPNProcessors 崩溃
- python - 如何从 Python 中的嵌套字典中一起打印所有键和值?
- html - 如何使多个不同高度的项目缩小到内容并且不会溢出它们的包装?
- git - 如何使用 JENKINS 比较覆盖率插件来检查与基本分支相比的拉取请求覆盖率?
- http - golang 多个 parseBody 用于 http.request