title: Using a variable from a different window
body: <p>I want to open a new window in JavaScript, and show some data from the opener window. Based on something I read I made this:</p>
  
  <p>MainWindow.html</p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
  &lt;script&gt;
  function OpenNewWindow()
  {
      this.MainWindowData = 123123;
      document.write(this.MainWindowData);
  
      var wnd = window.open("NewWindow.html");
      wnd.NewWindowData = 787878;
  }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;input type="button" value="Open Window" onclick="OpenNewWindow()"&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>NewWindow.html:</p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
  &lt;script&gt;
  function ShowData()
  {
      document.write("NewWindowData: " + this.NewWindowData + "&lt;br /&gt;");
      document.write("MainWindowData: " + window.opener.MainWindowData);
  }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;input type="button" value="Show Data" onclick="ShowData()"&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><br />
  The problem is that both variables remain undefined.<br />
  Thanks for the help in advance.</p>