
本文实例讲述了JS判断iframe是否加载完成的方法。分享给大家供大家参考,具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<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");
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>
|
或者:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<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");
if (iframe.attachEvent){
iframe.attachEvent("onload", function(){
alert("loaded");
});
} else {
iframe.onload = function(){
alert("loaded");
};
}
document.body.appendChild(iframe);
</script>
</body>
</html>
|
|