title: Read IFrame content using JavaScript
body: <p>Ok, This is my first time dealing seriously with IFrames and I cant seem to understand a few things:</p>
  
  <p>First the sample code I am testing with:</p>
  
  <pre><code>&lt;head&gt;
  &lt;script type="text/javascript"&gt;
  function init(){
    console.log("IFrame content: " + window.frames['i1'].document.getElementsByTagName('body')[0].innerHTML);
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="init();"&gt;
  &lt;iframe name="i1" src="foo.txt"/&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>the file "foo.txt" looks like this:</p>
  
  <pre><code>sample text file
  </code></pre>
  
  <p>Questions:</p>
  
  <p>1) The iframe seems to be behaving as a HTML document and the file text is actually part of the body instead. Why ? Is it a rule for an IFrame to be a HTML document. Is it not possible for the content of an iframe to be just plain text ??</p>
  
  <p>2) The file content gets wrapped inside a <strong><em>pre</em></strong> tag for some reason. Why is this so ? Is it always the case?</p>
  
  <p>3) My access method in the javascript is working but is there any other alternative? [native js solutions please] If the content is wrapped in a <strong><em>pre</em></strong> tag always then I will actually have to lookup inside the <strong><em>pre</em></strong> tag rather than lookup the <strong><em>innerHTML</em></strong></p>