【问题标题】:Open a new window on click of button in electron单击电子中的按钮打开一个新窗口
【发布时间】:2020-11-14 01:28:27
【问题描述】:

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

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

【问题讨论】:

    标签: javascript html jquery node.js electron


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-09
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多