title: Executing a function on iframe load with greasemonkey
body: <p>I am making a greasemonkey script for personal use, but I need it to execute a function when an iframe finishes loading. I tried having 2 seperate scripts, with one loading inside the iframe and executing the function, but the function is undefined since functions inside greasemonkey are in their own enviroment for security purposes.</p>
  
  <p>Is there anyway to execute a function from inside an iframe that exists in greasemonkey in the parent?</p>
  
  <p>Greasemonkey code for iframe parent:</p>
  
  <pre><code>frame2 = '[name="MainFrame"]';
  function appendtoiframe2(){
      $(frame2).contentWindow.$('body').append('&lt;div id="insecuremode_enable" style="position:fixed;bottom:0;background:#fff;"&gt;This div is now visible&lt;/div&gt;');
  });
  </code></pre>
  
  <p>Greasemonkey code for site inside iframe:</p>
  
  <pre><code>window.onload = function() {
      parent.appendtoiframe2();
  }
  </code></pre>
  
  <p>Thank you.</p>
  
  <p>Edit: I realized it might be silly doing it this way, instead of having the script just run in the site directly. But I only want this to execute if the site is in an iframe, which it's not always in. I am also trying to be able to control elements inside the parent from within the iframe.</p>