Home  >  Article  >  Web Front-end  >  Detailed explanation of message communication code in HTML5

Detailed explanation of message communication code in HTML5

零下一度
零下一度Original
2017-04-22 14:38:511705browse

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)







    
        HTML5 Messaging Template File (Two)
    
    
    

HTML5 Messaging Template File (Two)

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!

Statement:
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