2013-10-11 2 views
0

J'ai un iframe et je redirige des pages dans iframe. comment obtenir l'événement pour chaque page de fin de chargement.comment savoir la page Web est chargée

main.html

<html> 
<body> 
    <iframe src="http://www.child.html" id="childframe" style="height:100px"></iframe> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

    <script> 
    $(window).load(function(){ 
     var Body = $("#childframe").contents().find("body"); 
     var Element = Body.find("tag"); 
     // page is redirecting to new page 
     $(Element[0].click()); 

     window.setTimeout(reallyNext, 1000); 
     function reallyNext() { 
      //how to know inner page is loaded 
      var result= Body.find("#tag1"); 
      //how to get element from anotherpage.html 

      $(result).bind('DOMSubtreeModified', function(event) {     
       //how to reach here 
      }); 
     }  
    }); 
    </script> 
</body> 
</html> 

child.html

<html> 
<head></head> 

<body> 
    <p><a href="../anotherpage.html"></a><br></p> 
</body> 
</html> 

s'il vous plaît me dire comment connaître la page intérieure de iframe a fait le chargement?

Répondre

0

Vous pouvez utiliser le paremètre onload à l'intérieur de la balise body, qui s'exécute après le chargement de la page. Par exemple:

<body onload="myJavascriptFunction();" > 
0
$('#childframe').ready(function() { 
    ... 
}); 

ou

$('#childframe').load(function() { 
    ... 
}); 
0
<script language="javascript"> 
    iframe = document.getElementById("frameid"); 

    WaitForIFrame(); 

    function WaitForIFrame() { 
     if (iframe.readyState != "complete") { 
      setTimeout("WaitForIFrame();", 200); 
     } else { 
      done(); 
     } 
    } 

    function done() { 
     //some code after iframe has been loaded 
    } 
</script> 

Cela devrait fonctionner

0

Vous pouvez brancher sur l'événement javascript onLoad de l'élément <iframe /> (comme <iframe onLoad="myHandler" />, où myHandler est votre fonction js), ou, si vous utilisez jQuery , Avec l'extrait suivant:

$('#childframe').load(function() { 
    // your code handling the iframe loaded. 
}); 

Notez que votre code doit faire partie de la page qui contient la iframe pas la page en son sein.

+0

thnx tout le monde. – androidraj

Questions connexes