What cross-document messaging?
It's a communication mechanism between iFrame and it's contianer page.
We use iframes to sustain features offered by different domains, to be usable in our webpage.
Developers had been using different hard solutions like: server-side proxy, url-hashing (which are complex and are workaround solutions) to communicate between iframe and it's parent container page.
HTML5 now offers a direct solution to this scenario, using the postMessage().
Below is the sample example:
Below is the code for container page:
Below is the code for iFrame page:
we can even pass JSON as parameter.
parent -> o.contentWindow.postMessage(['one','two'],"*");
child(iframe) -> document.getElementById("parentData").value=e.data;
In the above sample codes, in place of "*" we should use, "http://<<remoteDomainName>>" for security purpose.
This feature supported in HTML5 offering browsers: ie8+, opera11 etc.
Download sample code files from this location.