Cross-Window Messaging
Another new feature from the HTML 5 specification, that just landed for Firefox 3, is the cross-origin postMessage API.
This particular API adds a new method to every window (including the current window, popups, iframes, and frames) that allows you to send textual messages from your current window to any other – regardless of any cross-domain policies that might exist.
Specifically, you’re given a new window.postMessage(“string”) method that generates a message DOM event on the document of the receiving document. This event object contains the message as a property: event.data which the receiving document can use however they see fit.
Obviously communicating in a cross-domain fashion is prone to abuse so there’s additional information passed along that can be used to verify the integrity of the message. The full list of properties include:
.data – A string holding the message passed from the other window.
.domain – The domain name of the window that sent the message.
.uri – The full URI for the window that sent the message.
.source – A reference to the window object of the window that sent the message.
The last property is especially important as it allows for two-way communication to occur between these windows.