在我的main.js
中,我正常创建主窗口(let mainWin = null
,在启动时初始化),并且当按下某个按钮时,我添加了子窗口。
let createNoteWin = null;
function createNoteEditWindow() {
createNoteWin = new BrowserWindow({ parent:mainWin, modal: true, width: 350, height: 500 , frame: false, show: false});
createNoteWin.on('close', function() {mainWin = null});
createNoteWin.loadFile('src/addNote.html');
createNoteWin.isResizable = false;
//createNoteWin.webContents.openDevTools();
}
ipcMain.on('open-noteedit-window', function newNoteWindowIPC(event, arg) {
createNoteEditWindow();
createNoteWin.show();
})
但是,当我关闭子窗口时,一旦按下另一个按钮,对我的主窗口的引用就会突然变成null
:
ipcMain.on('close-noteedit-window', function closeNoteeditWindowIPC(event, arg) {
mainWin.webContents //works fine
createNoteWin.close(createNoteWin);
mainWin.webContents; //throws an error since mainWin is null now, for some reason
})
有人知道为什么/如何发生吗?
答案 0 :(得分:0)
在第5行,您完全可以完成抱怨的事情:
createNoteWin.on('close', function() {mainWin = null});
这会将mainWin
设置为null
(“对我的主窗口的引用突然变为空”)。也许您是这个意思吗?
createNoteWin.on('close', function() {createNoteWin = null});