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 (i.e. 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.
addEventListener("click", function (e) { var window = remote. getCurrentWindow(); window. close(); });
Applications need to specify the -webkit-app-region: drag CSS property to tell Electron which regions are draggable. To make the whole window draggable, this CSS property is set to the style of the body tag in HTML. Applications can also use -webkit-app-region: no-drag CSS property to indicate the non-draggable area.
The only workaround is to use Menu. setApplicationMenu(null) , however, this will disable all the menu shortcuts like F11 for toggling fullscreen etc. In new versions of Electron, you can set autoHideMenuBar: true while creating browserWindow, pressing Alt will show the menu bar again. Save this answer.
Windows can be created from the renderer in two ways: clicking on links or submitting forms adorned with target=_blank. JavaScript calling window. open()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With