Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  7] [ 1]  / answers: 1 / hits: 23812  / 8 Years ago, mon, july 11, 2016, 12:00:00

In a main window, when a button is clicked, the second/child window will popped up via an ipc call.
This works when open the pop window on the first time. If I closed the pop window and reopen it again, I will get this error:




Uncaught Exception: Error: Object has been destroyed at Error (native)
at EventEmitter. (/home/xxxx/electron/fin/main.js:36:21) at emitOne
(events.js:96:13) at EventEmitter.emit (events.js:188:7) at
EventEmitter.
(/home/xxxx/electron/fin/node_modules/electron-prebuilt/dist/resources/electron.asar/browser/api/web-contents.js:156:13)
at emitTwo (events.js:106:13) at EventEmitter.emit (events.js:191:7)




#main.js on app ready:
mainWindow = new BrowserWindow({width: 800, height: 600})


mainWindow.loadURL(`file://${__dirname}/index.html`)


mainWindow.webContents.openDevTools()


mainWindow.on('closed', function () {

mainWindow = null
})

let popWindow = new BrowserWindow({parent: mainWindow, width: 450, height: 450, show: false});
popWindow.loadURL(`file://${__dirname}/app/pop.html`);
popWindow.webContents.openDevTools();

ipc.on('toggle-popwindow', function(){
popWindow.show();
});


And when I add hide() in the 'closed' method:



popWindow.on('closed', function (event) {
popWindow.hide();
});


I get this:



Uncaught Exception:
Error: Object has been destroyed


What is the problem?


More From » node.js

 Answers
11

If you close a browser window it will be destroyed, so you can't hide or show it again after that. Since you want to hide it and show it again later your should add a listener for the close event that calls preventDefault() and hides the window instead of closing it.


[#61425] Friday, July 8, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keric

Total Points: 572
Total Questions: 93
Total Answers: 97

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;