I'm building an app using electron 1.0 and unfortunately everywhere I look for guides and tutorials with it, no one uses electron 1 because it's so new.
I am trying to close a frameless window through the click of a button I made. I know the button works because I have check to make sure it can do simple things (ie change some text or whatever) but that's only when I use internal javascript but I am trying to use external javascript. When I use external the function never gets called...
const {remote} = require('electron');
const {BrowserWindow} = require('electron').remote;
document.getElementById("close-button").addEventListener("click", function (e) {
var window = remote.getCurrentWindow();
window.close();
});
That is my javascript file. I also know I am linking the file properly because I can use document.write() and it works.
What am I doing wrong here?
any help is greatly appreciated thanks!
Edit: Added remote line.
Although there is another reason why my event handler isn't working for my button. This question is closed and the answer has been accepted.
I don't know if you omitted the relevant import from the snippet you posted, but assuming you haven't remote
will be undefined when you call remote.getCurrentWindow()
. If you add const { remote } = require('electron');
to the top of your snippet I think your click handler will work as expected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.