title: Run Javascript in iFrame context
body: <p>I am attempting to run a script in a webpage, that should be executed in an <code>&lt;iframe&gt;</code>.  Right now I can call a function that is set within the <code>&lt;iframe&gt;</code>..  I'm just having issues running a script to the <code>&lt;iframe&gt;</code>'s context.</p>
  
  <p>Here's how I run a function set in the <code>&lt;iframe&gt;</code></p>
  
  <pre><code>$('#iframe').get(0).contentWindow.performSearch();
  </code></pre>
  
  <p>Now instead of calling the <code>preformSearch</code> function, I wish to run a script - for this example, this is the script...</p>
  
  <pre><code>console.log('worked!');
  </code></pre>
  
  <p>My actual script is a big one, so I won't put it here - for the sake of this question.</p>
  
  <p>So, is there any way to run that script through the <code>&lt;iframe&gt;</code>'s context?  For example, my first guess would be/was..</p>
  
  <pre><code>$('#iframe').get(0).contentWindow.function(){
   console.log('worked!');
  }
  </code></pre>
  
  <p>I've never messed with running functions through something like an <code>&lt;iframe&gt;</code> before though, so I'm stumped. </p>
  
  <p>Thanks for any help in advance!</p>
  
  <p><strong>NOTE</strong> I am using NW.js (Node-Webkit) to remove all <code>&lt;iframe&gt;</code> restrictions.</p>
  
  <p><strong>NOTE v2 The <code>preformSearch()</code> function was just a reforence on how I call functions in the frame.</strong></p>