title: Why is html5 postMessage not working for me?
body: <p>I use a few lines of javascript to create an iframe element, and then I'd like to send it a message, like this:</p>
  
  <pre><code>function loadiframe (callback) {
      var body = document.getElementsByTagName('body')[0];
      var iframe = document.createElement('iframe');
      iframe.id = 'iframe';
      iframe.seamless = 'seamless';
      iframe.src = 'http://localhost:3000/iframe.html';
      body.appendChild(iframe);
      callback();
  }
  
  loadiframe(function() {
      cpframe = document.getElementById('iframe').contentWindow;
      cpframe.postMessage('please get this message','http://localhost:3000');
      console.log('posted');
  })
  </code></pre>
  
  <p>And then, inside <a href="http://localhost:3000/iframe.html" rel="noreferrer">http://localhost:3000/iframe.html</a> (the source of the iframe) is something like this:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;does not work&lt;/title&gt;
  &lt;script&gt;
  window.addEventListener("message", receiveMessage, false);
  function receiveMessage(event) {
    if (event.origin == "http://localhost:3000") {
      document.write(JSON.stringify(event));
      document.write(typeof event);
    }
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But nothing happens... I even tried to not use the safety check for origin, but even like that nothing happens... Like it never got the message...</p>
  
  <p>Am I in some kind of async problem ? I tried to make sure the iframe was loaded before the postMessage went away...</p>
  
  <p>EDIT1: Also, no errors show on the console...</p>
  
  <p>EDIT2: I tried it in Google Chrome 11 and Firefox 4</p>
  
  <p>Thank you in advance.</p>