title: javascript: window.document returns null
body: <p>I have an HTML document named 'welcome.html' that uses an iframe referring 'main.html'. Inside 'inner.html' file an another iframe is used referring 'inner.html'. Now inside 'inner.html' i want to access elements of / or communicate between elements of main.html. I used the following way to do so in javascript,</p>
  
  <p>Method 1:</p>
  
  <pre><code>..
  ..
  var top_window = window.top;
  alert(top_window)    // gives top window object
  var main_window = top_window.frames['main-frame'] // assuming that 'main-frame' is the name given at the iframe declaration for 'main.html'
  alert(main_window)    // gives main window object
  var main_document = main_window.document
  alert(main_document)    // gives 'undefined'
  ..
  ..
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>..
  ..
  var parent_window = window.parent;
  alert(parent_window)    // gives parent window object, that is, 'main.html' window object
  var parent_document = parent_window.document
  alert(parent_document)    // gives 'null'
  ..
  ..
  </code></pre>
  
  <p>I want the document object of 'main.html's window object. Both my methods don't work out. Is there any sound solution or am I doing it in wrong manner?</p>
  
  <p>Thanks in advance.</p>