Home >Web Front-end >JS Tutorial >How to determine whether the iframe is loaded through JS
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>
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>
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!