javascript - 单击电子中的按钮打开一个新窗口
问题描述
我是电子和其他前端技术的新手。我正在尝试使用电子实现桌面应用程序。在此应用程序中,单击按钮应打开一个新窗口。主窗口正确打开,但单击按钮没有任何反应。我找不到错误。希望有人能提供帮助。提前致谢 :)
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" href="../assets/css/index.css">
</head>
<body>
<button id="addAlias" class="buttons">Add Alias</button>
<button id="generateKey" class="buttons">Generate Keys</button>
<button id="balance" class="buttons">Check Balance</button>
<button id="transaction" class="buttons">Send Money</button>
<script>
const button = document.getElementById('addAlias');
button.addEventListener('click', () => {
createBrowserWindow();
});
function createBrowserWindow() {
const remote = require('electron').remote;
const BrowserWindow = remote.BrowserWindow;
const win = new BrowserWindow({
height: 600,
width: 800
});
win.loadURL('https://stackoverflow.com/questions/53390798/opening-new-window-electron');
win.once('ready-to-show', () => {
win.show()
})
}
</script>
</body>
</html>
解决方案
当我使用您的代码时,控制台会记录错误:Uncaught ReferenceError: require is not defined
也许你会在这个线程上找到解决方案:Electron require() is not defined
推荐阅读
- reactjs - 无法从其他文件夹加载文件
- c - 在 C 中搜索子字符串
- scikit-learn - XGBoost 从助推器对象中获取分类器对象?
- visual-studio - 即使没有进行任何更改,Visual Studio 也会继续构建 Azure Functions v2 C# 项目
- java - “空”集合的目的是什么?
- php - MYSQL 查询中的数组问题 - Laravel
- vbscript - 连续循环的 VBScript 需要对错误更加健壮
- python - 在函数中使用 vars() [] 不起作用
- typescript - 如何使用嵌套接口限定 TypeScript 泛型类型
- xml - 在 XML 标头 SQL Server 中添加标头