This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3630|Reply: 1

[Other] Post-robot example of browser window communication

[Copy link]
Posted on 2/18/2023 9:24:06 PM | | | |
Requirements: Previously tested direct communication between browser windows using PostMessage, today we use a third-party library, post-robot, for cross-domain window communication.

JS determines whether the current page is an iframe or a popup window
https://www.itsvse.com/thread-10342-1-1.html

HTML5 PostMessage cross-window communication
https://www.itsvse.com/thread-10343-1-1.html

The post-robot is actually a further encapsulation of the PostMessage method of communication, with the following features (sending a message to another window):

  • Get a reply from the window you sent the message to
  • Passing a function to another window across different domains
  • Handle any errors that prevent your messages from passing
  • Don't worry about serializing your messages; Only send JavaScript objects
  • Use promises or async/await to wait for the response of the window you send the message to
  • Establish a secure message channel between two windows on a domain
  • Send a message between the parent window and the pop-up window in IE


NPM address:The hyperlink login is visible.
GitHub code address:The hyperlink login is visible.

First, let's take a look at the renderings as follows:



The parent window popups a child window, and then sends a message to the child window, and can get a response from the child window, of course, the child window can also get a response by sending a message to the parent window.HTTP-like request response pattern

The parent window code is as follows:

The sub-window code is as follows:

(End)





Previous:Angular-cli creates a specified version of the Angular project
Next:Download large projects using Git shallow clone source code
Posted on 2/19/2023 8:50:34 PM |
hellohellohello
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com