Umar Uzman
Umar Uzman

Reputation: 37

Unable to Close Window using remote in Electron JS

I have tried the following code to close a frameless window in Electron JS. But the window does not close when button is clicked. I am new for Electron, I am stuck here now.

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...

Upvotes: 2

Views: 219

Answers (1)

Umar Uzman
Umar Uzman

Reputation: 37

I got the problem solved. I had to add the following property to the new BrowserWindow Declaration.

webPreferences: {
        nodeIntegration: true
}

Although it is has not been necessary for older versions, for newer versions it is.

Upvotes: 1

Related Questions