Search code examples
node.jselectronipcmodal-window

Sending a message to the parent window in Electron


I have a rendering process open a modal window

import { remote } from 'electron';

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

How can I pass a message from the modalWindow back to its parent?


Solution

  • You have to use ipc communication.

    In the Main process:

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

    And in your modalWindow:

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

    ipcMain doc

    ipcRenderer doc