Close Electron frameless window not working

邮差的信 提交于 2020-01-02 04:54:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/37506005/close-electron-frameless-window-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!