title: How can I do cross-domain postMessage?
body: <p>The documentation for <a href="https://developer.mozilla.org/en/DOM/window.postMessage" rel="nofollow noreferrer">postMessage</a> implies that cross-domain messaging is possible. However:</p>
  
  <pre><code>// When the popup has fully loaded, if not blocked by a popup blocker
  </code></pre>
  
  <p>That isn't a very clear note of <strong>how</strong> to actually do it.</p>
  
  <p>Imagine two websites:</p>
  
  <ol>
  <li>[Parent] hosted on <code>qc-a.nfshost.com</code></li>
  <li>[Child] hosted on <code>qc-b.quadhome.com</code></li>
  </ol>
  
  <p>In the parent:</p>
  
  <pre><code>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');
  
    /* This doesn't work because same-origin policy prevents knowing when
       the opened window is ready. */
  
    w.postMessage('Vain attempt.', 'http://qc-b.quadhome.com');
  }
  </code></pre>
  
  <p>And, in the child:</p>
  
  <pre><code>document.addEventListener('message', function(e) {
    alert('Child got (from ' + e.origin + '): ' + e.data);
  }, false);
  
  window.opener.postMessage('Ready!', 'http://qc-a.nfshost.com');
  </code></pre>
  
  <p>All to no avail.</p>
  
  <p>Help?</p>