这篇文章主要介绍了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.jb51.net/";
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.php.cn/";
if (iframe.attachEvent){
iframe.attachEvent("onload", function(){
alert("loaded");
});
} else {
iframe.onload = function(){
alert("loaded");
};
}
document.body.appendChild(iframe);
</script>
</body>
</html>以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
以上就是如何通过JS判断iframe是否加载完成的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号