具有以下 HTML
<html>
<head>
<title>bar</title>
</head>
<!-- ... -->
</html>
并在主进程中的某处调用window.setTitle('foo');
,标题仍然是bar而不是被设置为foo
如果 HMTL 文件不包含标题节点,则setTitle()
工作正常
将setTitle
放入webContents
did-finish-load
事件中时有效。
为了将来参考,设置窗口标题的正确方法是先防止它自动更新为页面标题:
https://github.com/atom/electron/blob/master/docs/api/browser-window.md#event -page-title-updated
这里有一个完整的例子:
var win = new BrowserWindow({
width: 800,
height: 600,
title: 'My fixed title'
});
win.on('page-title-updated', (evt) => {
evt.preventDefault();
});
最有用的评论
这里有一个完整的例子: