酷乐教育
您的当前位置:首页如何通过JS判断iframe是否加载完成

如何通过JS判断iframe是否加载完成

来源:酷乐教育


这篇文章主要介绍了JS判断iframe是否加载完成的方法,提供了2种实现方法,可分别针对IE内核与非IE内核浏览器进行判断与操作,涉及javascript事件操作与判定技巧,需要的朋友可以参考下

本文实例讲述了JS判断iframe是否加载完成的方法。分享给大家供大家参考,具体如下:

<!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 = "//www.gxlcms.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 = "//www.gxlcms.com/";
if (iframe.attachEvent){
 iframe.attachEvent("onload", function(){
 alert("loaded");
 });
} else {
 iframe.onload = function(){
 alert("loaded");
 };
}
document.body.appendChild(iframe);
</script>
</body>
</html>

显示全文