简体   繁体   English

无法使用 Electron JS 中的远程关闭 Window

[英]Unable to Close Window using remote in Electron JS

I have tried the following code to close a frameless window in Electron JS.我尝试使用以下代码关闭 Electron JS 中的无框 window。 But the window does not close when button is clicked.但是单击按钮时 window 不会关闭。 I am new for Electron, I am stuck here now.我是 Electron 的新手,我现在被困在这里。

const electron = require('electron');
const path = require('path');
const remote = electron.remote;

const closeBtn = document.getElementById('closeBtn');

closeBtn.addEventListener('click', function(event) {
    var window = remote.getCurrentWindow();
    window.close();
});

Please tell me what I am supposed to do now.请告诉我我现在应该做什么。 Thanks in advance...提前致谢...

I got the problem solved.我解决了问题。 I had to add the following property to the new BrowserWindow Declaration.我必须将以下属性添加到新的 BrowserWindow 声明中。

webPreferences: {
        nodeIntegration: true
}

Although it is has not been necessary for older versions, for newer versions it is.尽管对于旧版本没有必要,但对于较新的版本是必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM