【问题标题】:Electron close and min button do not work电子关闭和最小按钮不起作用
【发布时间】:2020-10-06 14:41:35
【问题描述】:

你好 我是 js 和电子 js 的初学者 我使用的是 Windows 10 专业版,这是我的 main.js:

    const electron = require("electron");
    const { app, BrowserWindow } = electron;

    app.on("ready", () => {
      let win = new BrowserWindow({
        width: 800,
        height: 600,
        frame: false,
        nodeIntegration: false,
        title: "Myapp",
      });
      win.loadURL(`file://${__dirname}/index.html`);
      win.on("close", function (e) {
        e.preventDefault();
        win.destroy();
      });
    });

    exports.openWindow = (filename) => {
      let subwin = new BrowserWindow({ width: 1400, height: 900 });
      subwin.loadURL(`file://${__dirname}/` + filename + `.html`);
    };
    app.on("window-all-closed", () => {
      if (process.platform !== "darwin") {
        app.quit();
      }
    });

还有我的 index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Electron tutorials</title>
    <link rel="stylesheet" href="CSS/style.css" />
  </head>
  <body>
    <div id="content">
      <header>
        <div class="close-btn" id="close-btn">x</div>
        <div class="min-btn" id="min-btn">-</div>
      </header>
      <section>
        <div id="text">
          <h1>Hello Electron</h1>
        </div>
      </section>
    </div>
    <script src="Home.js"></script>
  </body>
</html>

还有我的 Home.js:

const remote = require("electron").remote;
const main = remote.require("./index.js");

document.getElementById("min-btn").addEventListener("click", function (e) {
  var window = remote.getCurrentWindow();
  window.minimize();
});

/*document.getElementById("max-btn").addEventListener("click", function (e) {
  var window = remote.getCurrentWindow();
  if (!window.isMaximized()) {
    window.maximize();
  } else {
    window.unmaximize();
  }
});*/

document.getElementById("close-btn").addEventListener("click", function (e) {
  var window = remote.getCurrentWindow();
  window.close();
});

** 我不知道如何使关闭、最小、最大按钮工作 我做了一些尝试,但都没有奏效 这在 Linux 中也不起作用 嘻嘻嘻嘻嘻嘻! 我疯了:)**

【问题讨论】:

    标签: javascript node.js windows electron native


    【解决方案1】:
    nodeIntegration: true
    

    将 false 更改为 true,以便您可以在渲染器中使用 Node API。 现在你正面临这个错误,因为你在渲染器上禁用了 Node API。

    Uncaught ReferenceError: require is not defined

    在您的情况下,此错误来自const remote = require("electron").remote;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      • 2021-09-23
      相关资源
      最近更新 更多