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:
Write a message processing function;
Register the message processing function: addEventListener('message', function, false);
The Sender needs to do the following:
postMessage('this is a message' , '//m.sbmmt.com');
Members contained in the event object event include:
data: passed Data;
origin: origin, origin includes three elements: host, protocol, port;
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!