communication between 2 browser windows in electron

前端 未结 3 527
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 23:54

I need to build an app that will span across multiple monitor screens, something like this: Electron suports multiple windows but how to comunicate between them?

3条回答
  •  醉梦人生
    2020-12-17 00:23

    Whenever we talk about communicating from one window to another window inside of an Electron application, you always want to be thinking of the IPC system, Inter Process Communication.

    So in one window you will listen for an event, for example, a form submittal.

    Once the form is submitted, you can take the text out of that input and emit an event to the Electron app.

    Then the Electron app will trigger its own event and send the event on over to the mainWindow which will receive the text and append it on to its list.

    You can start this with just vanilla JavaScript in the secondary window.html file like so:

      document.querySelector('form').addEventListener('submit', event => {
        event.preventDefault();
      });
    

    So the above assumes you are working with a form you are trying to submit.

提交回复
热议问题