Web Messaging (or cross-document messaging) it’s the API introduced to the HTML5 specification, allowing documents from various sources / domains to communicate in a secure manner. This is the basic level of security that allows to operate over the cross-site scripting protection level.
HTML5 Web Messaging
The basic method is postMessage, allowing to establish communication. Importantly, we have to access the Window object of the target document.
A simple example:
var o = document.getElementsByTagName('iframe'); o.contentWindow.postMessage('Hello!', 'http://the-site.com/');
But let’s look at specific, ready examples.
One of the best I have found on teamtreehouse:
working example can be started directly at codepen.io.
The whole works very well, and the example can be a base for our further solutions.
– interesting demo of capabilities on codeproject:
– a small buy useful tutorial:
– Dev Opera:
HTML5 Web Messaging is a very interesting feature worth remembering. It can be a quick way to get out of the problematic situation. And if we can — let’s use it.