Thursday, March 25, 2010

window.postMessage for cross domain communication

There are security concerns when communication between different HTML windows or frames occurs, that is why the communication is one way (from the child to the parent) and only if both windows are from the same domain.

Enter postMessage, an HTML5 feature, that allows sending messages that will be received as message events. Checking the origin (very important) and using with care the event parameter data, a simple string, is all that is required for a good relationship between friendly parties. window.postMessage is or will be implemented in Firefox, Opera, Safari, Chrome and even IE8.

Here is a link that describes the feature: Cross-Window Messaging.

Also, check out the jQuery cross-browser plugin that uses hashes to send data back and forth (naturally, the same mechanism should be implemented at both sides)


free internet radio said...

I use Opera, and no matter how many times I try, it just doesn't work for me... what may I do wrong?

Siderite said...

Hoping you are not a spammer (who the hell is called free internet radio?) I can only answer that I did not try this on Opera, but that it should work. If you give me a more detailed example, I would be willing to give you a more specific help.