打开一个新的窗口——const BrowserWindow = require(‘electron’).remote.BrowserWindow

demo.html部分:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">
        打开新的窗口
    </button>
    <div>

    </div>
    <script src="./render/demo.js"></script>
</body>
</html>

js部分:

const btn = this.document.querySelector("#btn");
const BrowserWindow = require('electron').remote.BrowserWindow
window.onload = function(){
    btn.onclick = ()=>{
        newWin = new BrowserWindow({
            width:750,
            height:500
        })
        newWin.loadFile('yellow.html');
        newWin.on('close',()=>{
            newWin = null
        })
    }
}

新的yellow.html部分:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div style="background-color: #f00;">
        yellow
    </div>
</body>
</html>

入口文件main部分:

var electron = require('electron') 

var app = electron.app   

var BrowserWindow = electron.BrowserWindow;

var mainWindow = null ;
app.on('ready',()=>{
    mainWindow = new BrowserWindow({
        width:500,
        height:500,
        webPreferences:{ nodeIntegration:true}
    })

    mainWindow.loadFile('demo.html')

    mainWindow.on('closed',()=>{
        mainWindow = null
    })

})