2013-10-11 63 views
0

我有一个iframe,我在iframe中重定向页面。 如何获取每个页面加载完成的事件。如何知道网页加载

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> 

请告诉我如何知道iframe的内页已经完成加载?

回答

0

您可以在加载页面后运行的body标签内使用onload paremeter。 例如:

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

$('#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> 

这应该工作

0

你可以(在onLoad的JavaScript <iframe />元素的事件像<iframe onLoad="myHandler" />,其中将myHandler挂钩是你的js函数),或者,如果使用jQuery ,用下面的代码片段:

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

注意,你的代码需要保存在其中的iframe不是页面的网页的一部分。

+0

thnx每个身体。 – androidraj