[英]My app doesn't close on button, electron.js
我有这个 electron.js 应用程序,我希望应用程序在单击closer
close 的文本时关闭。 这是我的代码:
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<title>Hello World!</title>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div class="content">
<h1>Hello</h1>
<h1 class="closer">UUUU</h1>
</div>
<script src="./renderer.js"></script>
<script src="./closer.js"></script>
</body>
</html>
main.js
初始化 electron
const {app, BrowserWindow} = require('electron')
const path = require('path')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 1200,
height: 600,
backgroundColor: "red",
frame: false,
webPreferences: {
nodeIntegration: true,
preload: path.join(__dirname, 'preload.js')
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// mainWindow.webContents.openDevTools()
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
closer.js
const { app } = require('electron');
const babi = function(){
const bubu = document.querySelector('.closer');
function bubub(){
bubu.innerHTML = "aganim";
app.quit();
}
bubu.addEventListener('click', bubub);
}
babi();
我的问题是单击按钮不起作用。 我应该怎么办?
[...bubu].forEach(bubu =>
bubu.addEventListener("click", bubuClose())
);
function bubuClose() {
bubu.innerHTML = "aganim";
window.close();
};
我认为你可以用这样的循环来做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.