如何禁用浏览器历史记录导航上的窗口标题更新?
我在创建时设置窗口的标题,并根据用户操作根据需要更新它。
但是,当使用历史导航功能 goBack
和 goForward
(通过react-router-dom useNavigate
)时,窗口的标题会自动更新并采用窗口加载的 HTML 文件中定义的标题值。由于我的 HTML 文件中没有定义任何标题,因此它只会使标题消失。
const appWindow = new BrowserWindow({
title: app.name,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
preload: path.join(__dirname, "../preloads/app.js")
}
});
appWindow.loadURL(getWindowUrl("index"));
有没有办法禁用此行为,使标题不会更新?
我使用的是电子版本17.1.0和react-router-dom 6.2.1。
I set the title of my window upon creation and update it as needed depending on the user actions.
However, when using the history navigation function goBack
and goForward
(via react-router-dom useNavigate
) the window's title is updated automatically and takes the value of the title defined in the HTML file loaded by the window. Since I don't have any title defined in my HTML file, it just makes the title disappear.
const appWindow = new BrowserWindow({
title: app.name,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
preload: path.join(__dirname, "../preloads/app.js")
}
});
appWindow.loadURL(getWindowUrl("index"));
Is there a way to disable this behaviour so the title doesn't update?
I'm using electron version 17.1.0 and react-router-dom 6.2.1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Electron 的
BrowserWindow
类具有“page-title-updated”
事件 能够取消本机窗口标题的更新。例如,这将取消源自窗口文档内的任何窗口标题更新。请注意,您可以使用
title
参数检查特定标题,以便仅禁止某些窗口标题。根据上面链接的文档,如果标题是通过将文档的 URL 作为窗口标题来创建的,则
explicitSet
将为false
。请注意,当您使用 Electron 的 API 设置窗口标题时,这不会触发。
Electron's
BrowserWindow
class has the"page-title-updated"
event which has the capability to cancel the update of the native window's title. For example,This will cancel any window title update which originated from within the window's document. Note that you could check for a specific title using the
title
parameter, so as to disallow only some window titles.As per the documentation linked above, in case the title was created by making the document's URL the window title,
explicitSet
will befalse
.Note that this will not trigger when you set the window title using Electron's API.