Terminator2122
Terminator2122

Reputation: 43

How to pass a variable from one HTML window to another in Electron?

I am creating an Electron Desktop App and I am struggling with what might be a very simple concept. Let's say I have two HTML pages (we'll call this foo.html and bar.html). foo.html is the initial page in my program and once the user clicks the submit or next button a new window is spawned (on top of foo.html) and shows the content of bar.html. Some values are produced and visualized and presented to the user in this bar.html. At this point both pages are open and once the user closes bar.html I want to pass some values from this page and display it in a text field or a table in my foo.html. I am confused on how to approach this problem. Essentially how do I pass back a value to an HTML page which has already been rendered?

Any help would be appreciated.

Thank you

Upvotes: 2

Views: 1837

Answers (1)

heatstreak
heatstreak

Reputation: 119

You need to use IPC which is used to communicate between two processes. In your case, a main window and a child window.

Refer to this documentation, ipcMain Documentation

The main window (foo.html) acts as the Main process. Above documentation shows how to send the message you want.

The child window (bar.html) acts as the Renderer process. Which is spawned by the Main process (foo.html). Refer this documentation on how to receive the sent message, ipcRenderer Documentation

You will also need to read about Parent and Child windows, in your case foo.html and bar.html respectively.

BrowserWindow Documentation

Upvotes: 1

Related Questions