Using PostMessage and onmessage in cross-document messaging
In order to achieve communication between different domains, it is necessary to add two domain names to the hosts file of the operating system for simulation.
Listing 3. Two different domain names are added to the Hosts file
127.0.0.1 parent.com 127.0.0.1 child.com
Embeds a child page through an IFRAME in the parent Web page and calls the PostMessage method in the JavaScript code to send the data to the child window.
Listing 4. A child page is embedded in the parent page and the PostMessage method is called to send the data
Listen for the OnMessage event in the child window and display the data sent by the parent window with JAVASCRIPT implementation.
Listing 5. Listen for the OnMessage event in the child window, showing the data sent by the parent window After work, try to be feasible.
HTML5 postmessage solve cross-domain issues