简体   繁体   中英

How to open second window on button click in electron

I have a button in my index.html that I would like to open a second window when clicked.

I have added the following to my 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');
}

On npm start, I'm getting the following error: 在此处输入图片说明

I had to create a second js file and input:

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');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM