|
var iframe = document.createElement("iframe");
iframe.src = "http://www.jb51.NET";
if (!/*@cc_on!@*/0) { //if not IE
iframe.onload = function(){
alert("Local iframe is now loaded.");
};
} else {
iframe.onreadystatechange = function(){
if (iframe.readyState == "complete"){
alert("Local iframe is now loaded.");
}
};
}
document.body.appendChild(iframe);
最近, Nicholas C. Zakas 文章《Iframes, onload, and document.domain》的評(píng)論中 Christopher 提供了一個(gè)新的判斷方法(很完美):
復(fù)制代碼 代碼如下:
var iframe = document.createElement("iframe");
iframe.src = "http://www.jb51.NET";
if (iframe.attachEvent){
iframe.attachEvent("onload", function(){
alert("Local iframe is now loaded.");
});
} else {
iframe.onload = function(){
alert("Local iframe is now loaded.");
};
}
document.body.appendChild(iframe);
幾點(diǎn)補(bǔ)充說(shuō)明:
IE 支持 iframe 的 onload 事件,不過(guò)是隱形的,需要通過(guò) attachEvent 來(lái)注冊(cè)。
第二種方法比第一種方法更完美,因?yàn)?readystatechange 事件相對(duì)于 load 事件有一些潛在的問(wèn)題。
JavaScript技術(shù):判斷iframe是否加載完成的完美方法,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。