Javascript 电子关闭和最小按钮不工作
你好 我是js和electron js的初学者 我正在使用Windows 10 pro,这是我的main.js:Javascript 电子关闭和最小按钮不工作,javascript,node.js,windows,electron,native,Javascript,Node.js,Windows,Electron,Native,你好 我是js和electron js的初学者 我正在使用Windows 10 pro,这是我的main.js: const electron = require("electron"); const { app, BrowserWindow } = electron; app.on("ready", () => { let win = new BrowserWindow({ width: 800, height: 60
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();
}
});
<!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>
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();
});
和my index.html:
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();
}
});
<!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>
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中也不起作用
嘿,帮帮忙!
我疯了:)**
将false更改为true,以便可以在渲染器中使用节点API。
现在,在禁用渲染器上的节点API时,您将面临此错误
未捕获引用错误:未定义require
在您的情况下,此错误来自const remote=require(“electron”).remote代码>