关闭电子无框窗口不起作用 [英] Close Electron frameless window not working

查看:64
本文介绍了关闭电子无框窗口不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用电子1.0的应用程序,不幸的是,我到处都在寻找使用它的指南和教程,没有人使用电子1,因为它太新了。

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.

我试图通过单击一个按钮来关闭无框窗口。我知道该按钮有效,因为我已经检查过该按钮,以确保它可以完成简单的操作(即更改一些文字或其他内容),但这仅在我使用内部javascript但我尝试使用外部javascript时才可用。当我使用外部函数时,永远不会调用该函数。

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();
    });

这是我的JavaScript文件。我也知道我可以正确链接文件,因为我可以使用document.write()并且可以正常工作。

That is my javascript file. I also know I am linking the file properly because I can use document.write() and it works.

这里我在做什么错了?

非常感谢任何帮助!

编辑:添加了远程线路。

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.

推荐答案

我不知道您是否从代码段中省略了相关导入您已发布,但假设您没有 remote ,则在调用 remote.getCurrentWindow()时将无法定义。如果将 const {remote} = require('electron'); 添加到代码段的顶部,我认为您的点击处理程序将按预期工作。

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.

这篇关于关闭电子无框窗口不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆