HTML5 Web Messaging
What is Web Messaging?
- Web messaging is an API which was introduced in WHATWG HTML5 draft specification.
- It allows the documents to communicate with one another across the different origins or the source domains.
|data||It contains the string data.|
|origin||It contains the domain name and the port.|
|lastEventId||It contains a unique identifier for the current message event.|
|source||It contains a reference of the original document window.|
|ports||It contains the data that is sent by any message port.|
A new web browsing context is required to be created before a cross-document message is sent by creating a new iframe or window.
Data is sent by using postMessage() which has two arguments as follows:
the message that is required to be sent.
the name of the origin.
Channel messaging is a two way communication between the browsing context. They are used for communication across multiple origins.
MessageChannel and MessagePort Objects
There are two ports which are created internally while a messageChannel is created. The two ports are used to send data and forward it to another browsing context.
the throw channel posts the message.
the data is sent.
the ports are closed.