title: Javascript/jQuery: calling function in another frame
body: <p>I'm new to the DOM and JavaScript and hitting on some problems when trying to call a function defined in a frame from the context of the top-level frame or Firebug.</p>
  
  <p>Given the below frameset:</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
      &lt;frameset cols="*" rows="81,*"&gt;
          &lt;frame id="topFrame" tabindex="1" name="topFrame" noresize="noresize" scrolling="No" src="hometop.aspx"/&gt; 
          &lt;frameset border="0" cols="214,*" frameborder="no" framespacing="0"&gt;
              &lt;frameset border="0" cols="*" frameborder="no" framespacing="0" rows="70,*"&gt;
                  &lt;frame tabindex="-1" id="chatFrame" name="chatFrame" scrolling="No" noresize="noresize" src=""/&gt;
                  &lt;frame tabindex="-1" id="leftFrame" name="leftFrame" noresize="noresize" src="leftFrame.aspx"/&gt;
              &lt;/frameset&gt; 
              &lt;frame tabindex="-1" id="mainFrame" name="mainFrame" src=""/&gt;
          &lt;/frameset&gt; 
          &lt;noframes&gt;Your browser does not support frameset.&lt;/noframes&gt; 
      &lt;/frameset&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'm trying to write a javascript hook that will call a javascript function defined in <strong>#leftFrame</strong> when the above document is first opened.  I'm performing this in a Firebug session with <strong><em>jQuery</em></strong> loaded.</p>
  
  <p><em>jQuery("#leftFrame")</em> returns a frame DOM element.  Now I'd like to execute my function (<em>openLink</em>, defined in plain old script tag in leftFrame.aspx) in the context of the frame.  My understanding is that the function will be a DOM node under the <em>leftFrame</em>'s document element.  However I can't get hold of the frame's document.</p>
  
  <p>I've tried:</p>
  
  <pre><code> jQuery("#leftFrame").document
   jQuery("#leftFrame").contentDocument
   jQuery("#leftFrame").find("html")
  </code></pre>
  
  <p>Also when inspecting the DOM tree in Firebug I can't see the <em>openLink</em> function under any DOM nodes as I'd expect.</p>
  
  <p>Can anyone help me out?</p>