Home > Web Front-end > JS Tutorial > How does jquery determine whether the iframe is loaded?

How does jquery determine whether the iframe is loaded?

coldplay.xixi
Release: 2020-12-01 16:08:34
Original
7760 people have browsed it

jquery Method to determine whether the iframe is loaded: 1. Use the [jQuery load()] method; 2. Use the [onreadystatechange] method; 3. Use the [attachEvent] method.

How does jquery determine whether the iframe is loaded?

The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

jquery Method to determine whether the iframe is loaded:

Method 1, jQuery load()

var frm = document.getElementById('myiframe');  
$(frm).load(function(){                             //  等iframe加载完毕  
dosomething();  
});
Copy after login

Method two, onreadystatechange

var iframe = document.createElement("myiframe");  
iframe.src = "http://www.baidu.com";  
if (!/*@cc_on!@*/0) { //如果不是IE,IE的条件注释  
    iframe.onload = function(){     
        alert("Local iframe is now loaded.");  
    };  
} else {  
    iframe.onreadystatechange = function(){ // IE下的节点都有onreadystatechange这个事件  
        if (iframe.readyState == "complete"){  
            alert("Local iframe is now loaded.");  
        }  
    };  
}  
document.body.appendChild(iframe);
Copy after login

Method three, attachEvent

var iframe = document.createElement("iframe");  
iframe.src = "http://www.baidu.com";  
  
if (iframe.attachEvent){  
    iframe.attachEvent("onload", function(){ // IE  
        alert("Local iframe is now loaded.");  
    });  
} else {  
    iframe.onload = function(){ // 非IE  
        alert("Local iframe is now loaded.");  
    };  
}  
  
document.body.appendChild(iframe);
Copy after login

The above is the detailed content of How does jquery determine whether the iframe is loaded?. 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