HTML5 postmessage solve cross-domain issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.