title: postMessage from local domain to remote domain
body: <p>With <a href="https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en" rel="nofollow">tampermonkey</a> I am running this Javascript inside an iframe in my page:</p>
  
  <pre><code>document.addEventListener("message", function(e){
    console.log('asd');
  }, false);
  </code></pre>
  
  <p>This way I could receive messages from parent window. I am using jQuery Mobile and have this HTML:</p>
  
  <pre><code>&lt;div data-role="page" data-url="/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia" tabindex="0" class="ui-page ui-body-c ui-page-active" style="min-height: 258px;"&gt;
      &lt;p class="notice"&gt;&lt;/p&gt;
  
      &lt;p class="alert"&gt;&lt;/p&gt;
      &lt;iframe id="test" name="scrap" src="http://en.wikipedia.org/wiki/List_of_hotels_in_Australia" width="100%"&gt;&lt;/iframe&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>But when I do this in browser console:</p>
  
  <pre><code>var win = document.getElementById("test").contentWindow; // undefined
  
  win
  Unsafe JavaScript attempt to access frame with URL http://en.wikipedia.org/wiki/List_of_hotels_in_Australia from frame with URL http://localhost:3001/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia. Domains, protocols and ports must match.
  Unsafe JavaScript attempt to access frame with URL http://en.wikipedia.org/wiki/List_of_hotels_in_Australia from frame with URL http://localhost:3001/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia. Domains, protocols and ports must match.
  Unsafe JavaScript attempt to access frame with URL http://en.wikipedia.org/wiki/List_of_hotels_in_Australia from frame with URL http://localhost:3001/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia. Domains, protocols and ports must match.
  Unsafe JavaScript attempt to access frame with URL http://en.wikipedia.org/wiki/List_of_hotels_in_Australia from frame with URL http://localhost:3001/scraps/new?for=http://en.wikipedia.org/wiki/List_of_hotels_in_Australia. Domains, protocols and ports must match.
  Window {}
  
  win.postMessage('aaaa')
  Error: SyntaxError: DOM Exception 12
  </code></pre>