Communicate between parent and child renderer process Electron JS

≡放荡痞女 提交于 2019-12-07 23:05:26

问题


Suppose we have the following 2 BrowserWindow instances created in main process:

let fooA = new BrowserWindow({width:800,height:800});
fooA.loadUrl(url.format({
    pathname: path.join(__dirname, './a.html'),
    protocol: 'file:',
    slashes: true
}));
let fooB = new BrowserWindow({parent:fooA});
fooB.loadUrl(url.format({
    pathname: path.join(__dirname, './b.html'),
    protocol: 'file:',
    slashes: true
}));

As you can see fooB is child of fooA Now each browsers window html file is associated with a renderer process: fooA is associated with rendererA.js and fooB is associated with rendererB.js

Now let's say I want to send a message from rendererA to rendererB Do I have to first send a message to main process and the after the main receives it to inform rendererB by using fooB.webContents.send('message-to-b',"rendererA says hello") or is there an easier way since fooA is the parent of fooB.

来源:https://stackoverflow.com/questions/44972482/communicate-between-parent-and-child-renderer-process-electron-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!