首页 > 解决方案 > 单击电子中的按钮打开一个新窗口

问题描述

我是电子和其他前端技术的新手。我正在尝试使用电子实现桌面应用程序。在此应用程序中,单击按钮应打开一个新窗口。主窗口正确打开,但单击按钮没有任何反应。我找不到错误。希望有人能提供帮助。提前致谢 :)

<!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>

在此处输入图像描述

标签: javascripthtmljquerynode.jselectron

解决方案


当我使用您的代码时,控制台会记录错误:Uncaught ReferenceError: require is not defined

也许你会在这个线程上找到解决方案:Electron require() is not defined


推荐阅读