【发布时间】: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