title: Cross domain postMessage, identify iFrame
body: <p>I use <code>postMessage</code> to send events from an iframe to it's parent document. I have control over both sides but the content comes from two different domains.</p>
  <p><img src="https://i.stack.imgur.com/W2g09.jpg" alt="enter image description here" /></p>
  <p>My simple problem is, that i can not identify the iFrame inside of it's parent callback method. The implementation looks like this:</p>
  <p><strong>In the iFrame:</strong></p>
  <pre><code>parent.postMessage(JSON.stringify({action: &quot;closeView&quot; }),'*');
  </code></pre>
  <p><strong>In the parent window:</strong></p>
  <pre><code>window.addEventListener('message',function(event) {
  if(event.origin !== 'https://example.com')
      return;
  
      // Parse message back to json
      var messageObject = JSON.parse(event.data);
      var source = event.source;
      /* this is returning: Window -URL- */
      console.log( source );
      /* This will throw Permission denied, although this code is inside of &quot;parent&quot; */
      console.log(source.parentNode);
  },false);
  </code></pre>
  <p>I want to identify a certain parent element of the iframe, which is (logically) inside of the parent document.</p>
  <p>When i try to use <code>event.source.parentNode</code> or some jQuery on said object, Firefox says, i can not do this to prevent XSS, error: <code>Error: Permission denied to access property 'parentNode'</code></p>
  <p>How can i get the parent element of the iFrame, that triggered the <code>postMessage</code> event listener?</p>