Onload function for an iframe inside another iframe

I have nested iframe and I would like to use the onload function on the inner frame. For example:

<script type="text/javascript">
 var testing = 'test';
 var curFrames;
 var curUrl;
 var mFrames;
 var cFrame;
 var editor;
 var editor2;

 window.onload=CodeOnLoad;

 //Javascript that runs on load
 function CodeOnLoad() {
  curFrames=document.getElementsByTagName("frame");

  console.log(curFrames[0])

  //onload for 1st frame  
  curFrames[0].onload = getInside;


  function getInside() {
   //onload for second frame - Not working 
   curFrames[0].contentDocument.getElementByid('the_iframe').onload = finalFrame;
  }

  function finalFrame() {

   curUrl= curFrames[0].contentDocument.getElementById("the_iframe").src;
   console.log(curUrl);

   if (curUrl.indexOf("post")!=-1)
   {
    mFrames=document.getElementsByTagName("frame");
    cFrame = mFrames[0].contentDocument.getElementById('the_iframe');
    editor = cFrame.contentWindow.tinymce.activeEditor;
    console.log(editor);    
   }
  }
 }

 </script>

      

Code (second callback):

curFrames[0].contentDocument.getElementByid('the_iframe').onload = finalFrame;

      

is never executed.

Is it possible to do this?

I want all frames to be loaded before any code is executed.

thank

+3


source to share


1 answer


Consider below how the windows tree

Parent window (P1)

---- Iframe 1 (I1)

-------- Iframe 2 (I2)

Now in p1, keep the say pfunc function where you code whatever you want to code



in I1 keep the function below

   function callParent()
   {
       parent.pfunc();
   }

      

in I2 when calling onload on below function

function callParent()
{
   parent.callParent();
}

      

this will do what you need.

+2


source







All Articles