【发布时间】:2021-11-22 10:50:27
【问题描述】:
我正在尝试从主进程创建两个窗口。第二个窗口应始终显示在第一个窗口的顶部。在Electron website 上,我读到我必须创建一个父窗口和一个子窗口来执行此操作。 这是我的代码:
let win;
let child;
function createWindow(){
// Create the browser window.
win = new BrowserWindow({width: 1024, height: 768, show: false});
child = new BrowserWindow({parent: win});
child.show();
win.once('ready-to-show', () => {
win.show()
})
// and load the index.html of the app.
win.loadURL(`file://${__dirname}/index.html`);
// Emitted when the window is closed.
win.on('closed', () => {
win = null;
});
}
app.on('ready', createWindow);
当我启动程序时,它会创建两个窗口,但子窗口并不总是在顶部。当我关闭父窗口(win)时,两个窗口都关闭了。 如何使子窗口始终显示在顶部? 我正在使用带有 Gnome 的 Fedora 24。
【问题讨论】:
-
你在child-win init之后有没有试过用这个方法?
child.setAlwaysOnTop(true); -
@tehcpu 感谢您的回复。我尝试添加 child.setAlwaysOnTop(true);它有效。
-
很好。不客气;)
-
@tehcpu 将此添加为答案。
-
@ShashwatKumar,好主意,完成了。
标签: javascript electron