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
coldplay.xixiOriginal
2020-12-01 16:08:347753browse

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();  
});

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);

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);

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!

Statement:
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