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è)新的判斷方法(很完美):
代碼如下:
var iframe = document.createElement("iframe");
iframe.src = "http://sc.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)題。
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com