在 Electron 中向父窗口发送消息

Posted

技术标签:

【中文标题】在 Electron 中向父窗口发送消息【英文标题】:Sending a message to the parent window in Electron 【发布时间】:2017-11-22 13:40:38 【问题描述】:

我有一个渲染进程打开一个模态窗口

import  remote  from 'electron';

let currentWindow = remote.getCurrentWindow();
let modalWindow = new BrowserWindow(width:800, heigh:500, parent:currentWindow);
modalWindow.loadURL('views/second.html');

如何将消息modalWindow 传回其父级?

【问题讨论】:

【参考方案1】:

你必须使用ipc通信。

在主进程中:

ipcMain.on('asynchronous-message', (event, arg) => 
   //manage data
)

在你的模态窗口中:

ipcRenderer.send('asynchronous-message', message)

ipcMain doc

ipcRenderer doc

【讨论】:

以上是关于在 Electron 中向父窗口发送消息的主要内容,如果未能解决你的问题,请参考以下文章