09 Electron 渲染进程与渲染进程之间的通信 BrowserWindow webContents
electron 渲染进程通过 localStorage 给另一个渲染进程传值
localStorage.setItem(key, value);
localStorage.getItem(key, value);
electron 通过 BrowserWindow 和 webContents 模块实现渲染进程和渲染进程的通信
webContent
:是一个事件发出者,它负责渲染并控制网页,也是 BrowerWindow 对象的属性。
需要了解以下几个知识点
获取当前窗口的 id
cosnt winId = BrowserWindow.getFocusedWindow().id;
监听当前窗口加载完成的事件
win.webContents.on('did-finish-load', function(event) {});
同一个窗口之间广播数据
win.webContents.on('did-finish-laod', function(event) {
win.webContent.send('msg', winId, 'this is from index.html data');
});
通过 id 查找窗口
let win = BrowserWindow.fromId(winId);
网友评论