创建子窗口的时候,要加一个属性parent指向父窗口
例子如下:
const {app,BrowserWindow} = require('electron');
function createWindow(){
//创建父窗口
parentWin = new BrowserWindow({
width:800,
height:600,
webPreferences: {
nodeIntegration: true
}
});
//创建子窗口
childWin = new BrowserWindow({
parent:parentWin,
width:300,
height:300,
webPreferences: {
nodeIntegration: true
}
});
//父窗口加载页面
parentWin.loadFile('index.html');
//子窗口加载页面
childWin.loadFile('child.html');
}
app.allowRendererProcessReuse = true;
app.on('ready',createWindow);
function createWindow(){
//创建父窗口
parentWin = new BrowserWindow({
width:800,
height:600,
webPreferences: {
nodeIntegration: true
}
});
//创建子窗口
childWin = new BrowserWindow({
parent:parentWin,
width:300,
height:300,
webPreferences: {
nodeIntegration: true
}
});
//父窗口加载页面
parentWin.loadFile('index.html');
//子窗口加载页面
childWin.loadFile('child.html');
}
app.allowRendererProcessReuse = true;
app.on('ready',createWindow);