title: How does one have access to frame's document object from another frame?
body: <p>Allright I have a page containing a frameset. One of these frames contains an asp page which contains a script written in javascript. <strong>This script needs to be able to access the content of an asp page which is contained inside another frame (in the frameset).</strong> Here's an example of the frameset code:</p>
  
  <pre><code>&lt;frameset name="foo"&gt;
      &lt;frame name="frame1" src="mydomain/path/of/the/page.asp"&gt;
      &lt;frame name="frame2" src="mydomain/path/of/the/other/page.asp"&gt;
  </code></pre>
  
  <p>So basically <strong>the script inside the page contained within frame1 tries to access the contents (more specifically tries to insert a DOM element) inside the page contained within frame2.</strong></p>
  
  <p>Both frames are on the same domain (and subdomain), so <strong>cross-scripting shouldn't be an issue</strong>. I can't edit the code outside the script so I'm forced to use frames. Here's my current code : </p>
  
  <pre><code>//Ideally, I would like to make sure the page contained within frame2 is loaded before trying to access it's elements. I still need to figure that one out. 
  $(document, window.parent).ready( function () {    
      //Assign id "foo" to frame2 using jQuery
      $('frame[name="foo"]', window.parent.document).attr("id", "foo"); 
      var doc;
      var testNode;
      var frmObj = window.parent.document.getElementById('foo'); 
      if (frmObj.contentDocument) { // DOM
          doc = frmObj.contentDocument;
      } 
      else if (frmObj.contentWindow) { // IE 
          doc = frmObj.contentWindow.document;
      }
      if (doc) {
          testNode = doc.createElement('div');
          testNode.Id = "testNode";
          doc.getElementByTagName('body').appendChild(testNode);
      }
  });  
  </code></pre>
  
  <p>The line containing getElementByTagName throws an error in IE 10 : </p>
  
  <blockquote>
    <p>SCRIPT438: Object doesn't support property or method 'getElementByTagName'</p>
  </blockquote>
  
  <p>It seems that the document object don't have any method named getElementByTagName. In that case, one could say that the document object doesn't exist, which is absurd since I've tested it's existence before trying to call it's methods. Knowing all this, <strong>how can we solve this issue?</strong></p>
  
  <p>Notes :</p>
  
  <ul>
  <li>I can't test the issue with another browser since external codes needed by all the pages uses vbscript.</li>
  <li>id "foo" is successfully added to frame2.</li>
  </ul>
  
  <p>Many thanks!</p>