title: run function on frame when window finish load
body: <p>I want to run function click on spesific id inside a frame, so i make two html file and i write the script like this</p>
  
  <p>the main html is this <code>index.html</code></p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
       &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
         &lt;script type="text/javascript"&gt;
         function autoClick(){
      document.getElementById('framing').contentWindow.document.getElementById('trig').click();
          }
         &lt;/script&gt;
       &lt;/head&gt;
       &lt;body onload="autoClick();"&gt;
              &lt;iframe name="framing" id="framing" src="testing.html" frameborder="0" scrolling="no" height="1200px" width="100%"&gt;&lt;/iframe&gt;
       &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>and another one is the <code>testing.html</code></p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
       &lt;head&gt;
        &lt;meta charset="UTF-8"&gt;
        &lt;script&gt;
         window.onbeforeunload = function(){
         return false; // This will stop the redirecting.
        }
        &lt;/script&gt;
       &lt;/head&gt;
      &lt;body&gt;
      &lt;div&gt;
        &lt;a id="trig" href='http://www.redirect.com/' target='iName'&gt;Home&lt;/a&gt;
      &lt;/div&gt;
          &lt;iframe src="about:blank" name="iName" frameborder="0" scrolling="no" height="1200px" width="100%"&gt;&lt;/iframe&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>so when <code>index.html</code> finish load the page, i want the function to click on the  <code>&lt;a id=trig" href='http://www.redirect.com/' target='iName'&gt;Home&lt;/a&gt;
  </code> on <code>testing.html</code> that inside frame <code>framing</code>
  and when it clicked, the <code>trig</code> will load a site <code>http://www.redirect.com</code> that will be contained inside <code>iName</code> frame, but the site <code>http://www.redirect.com</code> have a script that will redirect the TLD to the their site, so i put the script for preventing the page to break out the iframe `      
         window.onbeforeunload = function(){
         return false; // This will stop the redirecting.
        }</p>
  
  <p>this two html file is hosted on same domain. but when i try to run it, the function click is not triggered, anyone can help me?</p>
  
  <p>Thank you, and sorry for the bad english, it is not my native language</p>