Home > Web Front-end > JS Tutorial > body text

How to determine whether the iframe is loaded through JS

不言
Release: 2018-06-26 14:22:29
Original
3611 people have browsed it

This article mainly introduces the method of JS to judge whether the iframe is loaded. It provides two implementation methods, which can be judged and operated respectively for IE core and non-IE core browsers. It involves javascript event operation and judgment skills, which are required. Friends can refer to the following

The example of this article describes the method of JS to determine whether the iframe is loaded. Share it with everyone for your reference, the details are as follows:

<!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>
Copy after login

or:

<!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>
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to use JS to implement the WeChat payment pop-up window function

About js for passing array parameters to the background Controller method

The above is the detailed content of How to determine whether the iframe is loaded through JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template