0
点赞
收藏
分享

微信扫一扫

判断iframe是否加载完成

河南妞 2022-03-26 阅读 44


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title></title>

</head>

<body>

<script type="text/javascript">

var isIE = /msie/i.test(navigator.userAgent) && !window.opera;

var iframe = document.createElement("iframe");

iframe.src = "​​​http://www.baidu.com/​​​";

if (isIE) {

    iframe.onreadystatechange = function(){

        if(iframe.readyState == "loaded" || iframe.readyState == "complete"){

            alert("loaded");

        }

    };

} else {

    iframe.onload = function(){

        alert("loaded");

    };

}

document.body.appendChild(iframe);

</script>

</body>

</html>


或者:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title></title>

</head>

<body>

<script type="text/javascript">

var iframe = document.createElement("iframe");

iframe.src = "​​​http://www.baidu.com/​​​";

if (iframe.attachEvent){

    iframe.attachEvent("onload", function(){

        alert("loaded");

    });

} else {

    iframe.onload = function(){

        alert("loaded");

    };

}

document.body.appendChild(iframe);

</script>

</body>

</html>



举报

相关推荐

0 条评论