首页 > 解决方案 > 不使用 index.html 时的自定义电子标题栏

问题描述

使用以下代码时:

mainWindow.loadURL(`http://www.google.com/`);

我无法使用 css/html 制作自定义标题栏,因为我没有使用 index.html,因为如果我使用此代码则可以:

loaderWindow.loadURL(`file:///${__dirname}/loader.html`);

我尝试过自定义 npm 包,例如电子标题栏窗口和自定义电子标题栏。当我从 loadURL 显示外部页面时,似乎没有任何效果。

这是我当前在渲染器过程中实现的自定义电子标题栏:

let MyTitleBar = new customTitlebar.Titlebar({
  backgroundColor: customTitlebar.Color.fromHex('#03a9f4')
});

MyTitleBar.updateTitle('Test Title');

标签: javascriptelectrontitlebar

解决方案


您应该能够使用setTitle 文档

mainWindow.webContents.on('did-finish-load', () => {
  mainWindow.setTitle('Test Title');
});

推荐阅读