最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Object has been destroyed Exception after reopen BrowserWindow on button click in Electron - Stack Overflow

programmeradmin5浏览0评论

I am new to Electron Framework, developing simple desktop application with Electron. Problem is that, when i open a new window in electron app and close it using menu bar close button and again try to open it, then it throws "Object has been destroyed Exception". How do i retain BrowserWindow object even though close button clicked???

I am new to Electron Framework, developing simple desktop application with Electron. Problem is that, when i open a new window in electron app and close it using menu bar close button and again try to open it, then it throws "Object has been destroyed Exception". How do i retain BrowserWindow object even though close button clicked???

Share Improve this question asked Dec 14, 2017 at 5:41 user7808817user7808817 1072 silver badges12 bronze badges 1
  • show your code please – pergy Commented Dec 14, 2017 at 13:02
Add a ment  | 

2 Answers 2

Reset to default 3

If anyone es across this and the other answer didn't help. I was having a similar issue where I was handling the closing of a window. I fixed it by using window.destroy() instead of window.close()

The BrowserWindow object is supposed to be destroyed when closed. You'll need to instantiate a new one when reopening instead of trying to reuse the reference.

Edit:

How you instantiate it depends on if you're doing it from the main process (i.e. "Main.js") or the renderer process.

From the main process, it would look like:

var electron = require("electron");
var url = require("url");
var path = require("path");
var newWindow = new electron.BrowserWindow({
    width: 700,
    height: 500
});

newWindow.loadURL(url.format({
    pathname: path.join(__dirname, '/SomeStuff.html'),
    protocol: 'file:',
    slashes: true
}));

If instantiating from the renderer process, you need to use the "remote" object to access the main process. So it'd be like:

var newWindow = new electron.remote.BrowserWindow({
    width: 700,
    height: 500
});
发布评论

评论列表(0)

  1. 暂无评论