方法一、jQuery load()
var frm = document.getElementById('myiframe');
$(frm).load(function(){ // 等iframe加载完毕
dosomething();
});
方法二、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);
方法三、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);