The documentation for postMessage implies that cross-domain messaging is possible. But:
// When the popup has fully loaded, if not blocked by a popup blocker
This is not a very clear point on how to do this.
Imagine two websites:
- [Parent] is hosted at
qc-a.nfshost.com - [Baby] posted on
qc-b.quadhome.com
In parent:
document.addEventListener('message', function(e) { alert('Parent got (from ' + e.origin + '): ' + e.data); e.source.postMessage('Round-tripped!', 'http://qc-b.quadhome.com'); }, false); function go() { var w = window.open('http://qc-b.quadhome.com', 'test'); w.postMessage('Vain attempt.', 'http://qc-b.quadhome.com'); }
And, in the child:
document.addEventListener('message', function(e) { alert('Child got (from ' + e.origin + '): ' + e.data); }, false); window.opener.postMessage('Ready!', 'http://qc-a.nfshost.com');
All to no avail.
reference
javascript html5 cross-domain postmessage
Scott robinson
source share