postMessage method (window)
Provides communication between two documents regardless of their location.
Note: The postMessage method is supported in Internet Explorer from version 8, Firefox from version 3 and Opera from version 9.5.
Note: The postMessage method is synchronous in Internet Explorer and asynchronous in other browsers.
- the data property contains the message,
- the origin property retrieves the scheme, hostname and port of the document that invoked the postMessage method,
- the source property refers to the window object that contains the document that invoked the postMessage method.
- the lastEventId property returns the identifier of the last message.
You can find the related objects in the Supported by objects section below.
|Required. String that specifies the message.|
Required in Firefox, Google Chrome and Safari, optional in Internet Explorer and Opera. String that specifies the URI (scheme, hostname and port) of the target document's location.
Before the message is dispatched, the current location of the target document is checked. If it does not match the specified URI, then the message will not be dispatched. This parameter can be useful if you want to be sure of the location of the target document before dispatching the message (for example secret data needs to be sent).If you do not need this feature, use the '*' string literal.
This method has no return value.
Example HTML code 1:
This example illustrates the use of the postMessage method:
Did you find this example helpful?
User Contributed Comments