• electron 自己注册回调 hook


    electron 中webview如何与主进程渲染进程进行事件监听通信

    zpzxgcr 2018-10-12 23:26:35 1006 收藏
    展开
    直接上代码

    const webview = document.querySelector('webview');
    webview.addEventListener('dom-ready', () => {
    webview.openDevTools();
    console.log('渲染进程在webview加载完之后发送消息')
    })
    //上面是渲染进程发送消息给webview

    webview.addEventListener('ipc-message', () => {
    console.log('收到webview发送的消息');
    })

    webview也就是网页这么接收

    if ( window.require('electron') ) {
    let ipcRenderer = window.require('electron').ipcRenderer;
    ipcRenderer && ipcRenderer.on('webmsg', (e, msg) => {
    console.log(msg,'收到的消息');
    });
    ipcRenderer && ipcRenderer.sendToHost('我已经收到消息了');
    }
    //有一点需要注意 如果你是webpack 或者用了browserify模块化的方案的 不要直接使用require不然就会报错
    //我们要使用window全局对象下的require就没有关系

    上面就是接收到消息并且发送消息的相关操作

    内容很简单我就没有具体说了,看代码还不明白的话可以在下面留言
    ————————————————
    版权声明:本文为CSDN博主「zpzxgcr」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_25842063/article/details/83034133

  • 相关阅读:
    01 Vue的起步和插值表达式
    06 扩展的对象的功能
    05 解构赋值
    04 函数之扩展运算符、箭头函数
    03 函数之默认值、剩余参数
    02 模板字符串
    01 let和const命令
    28 Bootstrap排版
    27 Bootstrap的列偏移
    26 Bootstrap的栅格系统
  • 原文地址:https://www.cnblogs.com/bigben0123/p/13066824.html
Copyright © 2020-2023  润新知