【问题标题】:How to open second window on button click in electron如何在电子中单击按钮时打开第二个窗口
【发布时间】:2020-07-08 15:25:46
【问题描述】:

我的 index.html 中有一个按钮,我想在单击时打开第二个窗口。

我在 index.js 中添加了以下内容:

const button = document.getElementById('newtask');
button.addEventListener('click', () => {
  newtaskwindow();
});

function newtaskwindow() {
  const BrowserWindow = remote.BrowserWindow;
  const win = new BrowserWindow({
    height: 400,
    width: 600
  });

  win.loadURL('createtasks.html');
}

在 npm 启动时,我收到以下错误:

【问题讨论】:

    标签: javascript html css electron


    【解决方案1】:

    我必须创建第二个 js 文件并输入:

    const button = document.getElementById('newtask');
    button.addEventListener('click', () => {
      newtaskwindow();
    });
    
    function newtaskwindow() {
      const remote = require('electron').remote;
      const BrowserWindow = remote.BrowserWindow;
      const win = new BrowserWindow({
        height: 600,
        width: 800
      });
    
      win.loadURL('createtasks.html');
    }
    

    【讨论】:

    • 它不起作用,新方法也是使用loadFile
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 2019-10-07
    相关资源
    最近更新 更多