title: Accessing JavaScript variable in an iframe, from the parent window on same domain
body: <p>I am fairly new to JavaScript and I am trying to get value of a variable from an embedded iframe. I have resorted to basic testing to make sure I am getting the method right...</p>
  
  <p>I have tried the common suggestions and everything returns 'undefined'. I want to use the variable in an onclick event.</p>
  
  <p>In the iframe content I have stripped everything and just for testing have this:</p>
  
  <pre><code>&lt;script&gt;
  var test = "test";
  &lt;/script&gt;
  </code></pre>
  
  <p>in the parent window I have done this:</p>
  
  <pre><code>&lt;iframe src="iframe.html" id="iframe" width="200" height="100"&gt;&lt;/iframe&gt;
  
  &lt;script&gt;
  var myVar = window.frames[0].window.test;
  &lt;/script&gt;
  &lt;a href="#" onclick='alert(myVar)' id="link"&gt;Click&lt;/a&gt;
  </code></pre>
  
  <p>I have tried the options suggested here: <a href="https://stackoverflow.com/questions/6035673/grab-global-variable-from-an-embedded-iframe">grab global variable from an embedded iframe</a></p>
  
  <p>Everything I do returns undefined... am I doing something fundamentally wrong?</p>
  
  <p>Thanks in advance..</p>