Posted on 2011-06-02 18:36
xcp 閱讀(7410)
評(píng)論(0) 編輯 收藏 所屬分類:
Javascript
般來(lái)說(shuō),我們判斷 iframe 是否加載完成其實(shí)與
判斷 JavaScript 文件是否加載完成 采用的方法很類似:
var iframe = document.createElement("iframe");
iframe.src = "http://www.planabc.net";
if (!/*@cc_on!@*/0) { //if not IE
iframe.onload = function(){
alert("Local iframe is now loaded.");
};
} else {
iframe.onreadystatechange = function(){//ie
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://www.planabc.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);
我自己的實(shí)例:
<div class="contentRight">
<iframe name="myframe" id="myframe" src="" frameborder="0" scrolling="no" width="100%" height="500"></iframe>
</div>
var iframe = document.getElementById("myframe");
iframe.src="<%=request.getContextPath()%>/jsp/dwgl/hygl/zdhygl/dwgl_hygl_zdhygl_cx_part2.jsp";
if (iframe.attachEvent){
iframe.attachEvent("onload", function(){
get_list_data_nopar();
});
}else{
iframe.onload = function(){
get_list_data_nopar();
};
}
幾點(diǎn)補(bǔ)充說(shuō)明:
1、IE 支持 iframe 的onload 事件,不過(guò)是隱形的,需要通過(guò) attachEvent 來(lái)注冊(cè)。
2、第二種方法比第一種方法更完美,因?yàn)?readystatechange 事件相對(duì)于 load 事件有一些潛在的問(wèn)題。
名稱: ?4C.ESL | .↗Evon
口號(hào): 遇到新問(wèn)題?先要尋找一個(gè)方案乄而不是創(chuàng)造一個(gè)方案こ
mail: 聯(lián)系我