window.postMessage() method safely enables cross-origin communication between two pages regardless of their location.
Note: A page from abc.com can communicate with a page from xyz.com.
In the following example, we will communicate with a page in 2braces.com (another domain).
|targetWindow||Required||A reference to the window that will receive the message.|
Methods for obtaining such a reference include:
window.open - to spawn a new window and then reference it.
window.opener - to reference the window that spawned this one.
HTMLIFrameElement.contentWindow - to reference an embedded <iframe> from its parent window.
window.parent - to reference the parent window from within an embedded <iframe>
window.frames + an index value
|message||Required||Data to be sent to the other window|
|targetOrigin||Required||Specifies what the origin of targetWindow must be for the event to be dispatched.|
Please do google search for:
Join Our Channel
This channel is primarily useful for Full Stack Web Developer.