Html5 cross-document message transmission example _ html5 tutorial skills-

Source: Internet
Author: User
To implement cross-document message transmission, you must first listen to the message event of the window object, and then use the postMessage () method of the window object to send messages to other windows. Next, we will give you a detailed introduction, if you are interested, refer to the following to listen to the message event of the window object.

The Code is as follows:


Window. addEventListener ("message", function (event ){
// Processing program code
}, False );


Use the postMessage () method of the window object to send messages to other windows. The definition of this method is as follows:

The Code is as follows:


Otherwindow. postMessage (message, targetOrigin );


This method uses two parameters: the first parameter is the message text sent, but it can also be any JavaScript Object (converted to text through JSON ); the second parameter is the URL address of the message receiving Object window. You can use the wildcard "*" in the URL string to specify all addresses. However, we recommend that you use an accurate URL address. Otherwindow is a reference to the window object to be sent. You can use window. the open () method returns this object, or the window. the frames array specifies the sequence number (index) or name to return the window object of a single frame.
Example

The Code is as follows:






Cross-document message transmission example Main Document

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.