Close The frame electronic window does not work

I create an application using electron 1.0 and, unfortunately, everywhere I look for reference books and tutorials with it, no one uses electron 1 because it is so new.

I am trying to close a frameless window by pressing the button I made. I know that a button works because I have a check to make sure that it can do simple things (i.e., change some text or something else), but this is only when I use internal javascript, but I am trying to use external javascript. When I use external, the function is never called ...

const {remote} = require('electron'); const {BrowserWindow} = require('electron').remote; document.getElementById("close-button").addEventListener("click", function (e) { var window = remote.getCurrentWindow(); window.close(); }); 

This is my javascript file. I also know that I am attaching the file correctly because I can use document.write () and it works.

What am I doing wrong here?

any help gratefully thanks!

Edit: added remote line.

Although there is another reason why my event handler does not work for my button. This question is closed and the answer is accepted.

+5
source share
1 answer

I don’t know if you missed the appropriate import from the published snippet, but assuming that there will be no remote when you call remote.getCurrentWindow() . If you add const { remote } = require('electron'); to the beginning of my snippet, I think your click handler will work as expected.

+4
source

All Articles