title: How JavaScript objects passed with postMessage
body: <p>I have been playing with <code>HTML</code> <code>postMessage</code> and managed to pass messages between my web page and the popup window it opens.</p>
  
  <p>index.html:</p>
  
  <pre><code>var popup;
  window.onload = function () {
      console.log("window.onload");
      var btn = document.getElementById('signin');
      btn.addEventListener('click', signin);
  };
  
  var pollTimer;
  
  function signin(e) {
      console.log("window.onload - signin");
      popup = window.open("http://www.olcayertas.com/testqa/redirect.html", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=10, left=700, width=600, height=600");
  
      pollTimer = window.setInterval(function () {
  
          if (popup.closed !== false) { // !== is required for compatibility with Opera
              window.clearInterval(pollTimer);
              document.getElementById('signin').style.visibility = 'hidden';
          }
  
          e.preventDefault();
          popup.postMessage('message', 'http://www.olcayertas.com/testqa/index.html');
          console.log("sendMessage - Message sent!!!");
  
      }, 500);
  }
  
  function receiveMessage(event){
      window.clearInterval(pollTimer);
  }
  
  window.addEventListener("message", receiveMessage, false);
  </code></pre>
  
  <p>popup.html:</p>
  
  <pre><code>console.log("script");
  window.onload = first();
  var messageEle;
  
  function receiveMessage(e) {
      console.log("receiveMessage");
      messageEle = document.getElementById('message');
      messageEle.innerHTML = "Message Received: " + e.data;
      e.source.postMessage("Mesaj alındı!", e.origin);
  }
  
  function first() {
      console.log("first");
      window.addEventListener('message', receiveMessage);
  }
  </code></pre>
  
  <p>What I need is redirect the user to an other page by setting <code>top.location</code> parameter in my popup window and pass the <code>e.source</code> parameter to this page so it can also send message to <code>index.html</code>. Since I do not know how the <code>e</code> parameter of the <code>receiveMessage(e)</code> function passed I am stuck. </p>
  
  <p>How can I do that?</p>
  
  <p>Thanks in advance.</p>