javascript - 如何在 Electron 点击按钮中打开第二个窗口

标签 javascript html css electron

我的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 start上,出现以下错误:
enter image description here

最佳答案

我必须创建第二个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');
}

关于javascript - 如何在 Electron 点击按钮中打开第二个窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60893635/

相关文章:

php - 为什么 $(document).ready 不为我开火?

javascript - 如何旋转 WebGL 曲面分割中的各个三 Angular 形?

javascript - 如何打印 HTML 页面的选定部分?

javascript - 从外部 Angular Controller 访问变量

javascript - Angular 5 : accessing variable in component from loop

javascript - 在数据库问题中保存模式消息

c# - 如何在 winform 中显示 html 格式的内容(无图像)?

jquery - 使用 jQuery 在悬停时显示链接

php - 如何设置此 PHP 打印的 HTML 表单以保留在 <p> 标记内?

CSS:在内容中编码字符后