JS判断iframe是否加载完成的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

JS判断iframe是否加载完成的方法

Quber   2020-05-15 我要评论

本文实例讲述了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.qb5200.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.qb5200.com/";
if (iframe.attachEvent){
  iframe.attachEvent("onload", function(){
    alert("loaded");
  });
} else {
  iframe.onload = function(){
    alert("loaded");
  };
}
document.body.appendChild(iframe);
</script>
</body>
</html>

希望本文所述对大家JavaScript程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们