Detailed explanation of message communication code in HTML5

零下一度
Release: 2017-04-22 14:38:51
Original
1762 people have browsed it

HTML5 supports cross-document messaging (Cross-Document Messaging).

Since message communication is used, events must occur. According to the generation and consumption of events, we can find the sender and receiver, that is, Sender and Listener.

Litener needs to do the following work:

  1. Write a message processing function;

  2. Register the message processing function: addEventListener('message', function, false);

The Sender needs to do the following:

  1. postMessage('this is a message' , '//m.sbmmt.com');

Members contained in the event object event include:

  1. data: passed Data;

  2. origin: origin, origin includes three elements: host, protocol, port;

  3. source: source object;

Okay, let’s look at an example. This example shows nesting pages within pages and sending messages to child pages:

The parent page is as follows:

     HTML5 Messaging Template File (One)     

HTML5 Messaging Template File (One)

Copy after login
     HTML5 Messaging Template File (Two)    

HTML5 Messaging Template File (Two)

Copy after login

Students who need to learn html5 please pay attention to php Chinese websitehtml5 video tutorial, many html5 online video tutorials can be watched for free!

The above is the detailed content of Detailed explanation of message communication code in HTML5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!