The scene

background

I believe you are familiar with electron. Many applications generate clients by embedding a box in electron, which makes it extremely difficult to communicate with THE HTML page. Besides, ipcRenderer, ipcMain and webContents. At this time, SAO operation appeared!

The solution

'use strict';

const APP = {
    version: "1.0.0",
    author: "[email protected]",
    root: __dirname,
    debug: true
};

const electron = require("electron");
const {BrowserWindow, ipcMain} = electron;

electron.app.on("ready", () => {

    ipcMain.on("app.quit".function (event) {
        electron.app.quit();
    });


    let win = new BrowserWindow();
    win.loadURL("http://www.baidu.com");

    win.webContents.executeJavaScript(`
    document.getElementById("lg").addEventListener("click".function(){
        require("electron").ipcRenderer.send("app.quit"); }); `)});Copy the code

conclusion

Learning again