[英]Can't close a Window in electron
所以我正在學習關於電子的教程,但我被困在這個階段,我無法使用關閉按鈕來關閉當前窗口,有人可以幫忙嗎?
JavaScript 代碼:
const electron = require('electron')
const path = require('path')
const remote = electron.remote
const closeBtn = document.getElementById('closeBtn')
closeBtn.addEventListener('click', function (event) {
var window = remote.getCurrentWindow();
window.close();
})
html代碼:
<body>
<p class="notify">Notify me when BTC reaches..</p>
<div class="row2">
<div>
<input id="notifyVal" placeholder="USD">
</div>
<button id="updateBtn">Update</button>
</div>
<a id="closeBtn">Close Window</a><br>
</div>
<script src="add.js"></script>
</body>
CSS代碼:
body {
background:#DFDFDF;
color:#000;
overflow:hidden;
}
p.notify {
background:#C3C3C3;
margin:0;
padding: 20px;
text-transform:uppercase;
-webkit-app-region: drag;
}
.row2 {
width:100%;
display: grid;
grid-template-columns: auto auto;
padding:20px;
}
input {
padding:12px;
}
#closeBtn {
cursor:pointer;
padding:20px;
text-decoration:underline;
}
我不認為我打錯了因為我什至復制了代碼但它仍然不起作用我可以創建新窗口但我無法關閉它們。
這可能是因為 nodeIntegration 在主進程中沒有設置為 true。 由於您正在從渲染器進程 (add.js) 調用 require 方法,因此您可能需要將 nodeIntegration: true 添加到主進程(可能是 main.js)中的 webPreferences。 嘗試做這樣的事情:
mainWindow = new BrowserWindow({
width: 500,
height: 400,
frame: false,
webPreferences: {
nodeIntegration: true
}
});
如果控制台中出現任何錯誤,請告訴我們,他們將幫助調試問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.