title: Get IFrame's document, from JavaScript in main document
body: <p>I have this HTML code:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/javascript"&gt;
        function GetDoc(x)
        {
          return x.document ||
            x.contentDocument ||
            x.contentWindow.document;
        }
  
        function DoStuff()
        {
          var fr = document.all["myframe"];
          while(fr.ariaBusy) { }
          var doc = GetDoc(fr);
          if (doc == document)
            alert("Bad");
          else 
            alert("Good");
        }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;iframe id="myframe" src="http://example.com" width="100%" height="100%" onload="DoStuff()"&gt;&lt;/iframe&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is that I get message "Bad". That mean that the document of iframe is not got correctly, and what is actualy returned by GetDoc function is the parent document.</p>
  
  <p>I would be thankful, if you told where I do my mistake. (I want to get document hosted in IFrame.)</p>
  
  <p>Thank you.</p>