Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何知道网页已加载_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何知道网页已加载

Javascript 如何知道网页已加载,javascript,jquery,html,Javascript,Jquery,Html,我有一个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/

我有一个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>

$(窗口).load(函数(){
var Body=$(“#childframe”).contents().find(“Body”);
var元素=Body.find(“标记”);
//页面正在重定向到新页面
$(元素[0]。单击());
setTimeout(reallyNext,1000);
函数reallyNext(){
//如何知道内部页面已加载
var result=Body.find(“#tag1”);
//如何从anotherpage.html获取元素
$(结果).bind('domsubtreemedited',函数(事件){
//到这里怎么走
}); 
}    
});
child.html

<html>
<head></head>

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



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

您可以在body标记中使用onload参数,该参数在页面加载后运行。 例如:

<body onload="myJavascriptFunction();" >


iframe=document.getElementById(“frameid”);
WaitForIFrame();
函数WaitForIFrame(){
如果(iframe.readyState!=“完成”){
setTimeout(“WaitForIFrame();”,200);
}否则{
完成();
}
}
函数完成(){
//iframe加载后的一些代码
}

这应该可以工作

您可以钩住
元素的
onLoad
javascript事件(比如
,其中myHandler是您的js函数),或者,如果使用jQuery,可以钩住以下代码片段:

$('#childframe').load(function() {
   // your code handling the iframe loaded. 
});
请注意,您的代码需要是包含
iframe
的页面的一部分,而不是其中的页面

$('#childframe').load(function() {
    ...
});
<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>  
$('#childframe').load(function() {
   // your code handling the iframe loaded. 
});