般來說,我們判斷 iframe 是否加載完成其實與 判斷 JavaScript 文件是否加載完成 采用的方法很類似:
最近, Nicholas C. Zakas 文章《Iframes, onload, and document.domain》的評論中 Christopher 提供了一個新的判斷方法(很完美)
我自己的實例:
<div class="contentRight">
<iframe name="myframe" id="myframe" src="" frameborder="0" scrolling="no" width="100%" height="500"></iframe>
</div>
幾點補充說明:
1、IE 支持 iframe 的onload 事件,不過是隱形的,需要通過 attachEvent 來注冊。
2、第二種方法比第一種方法更完美,因為 readystatechange 事件相對于 load 事件有一些潛在的問題。
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);
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》的評論中 Christopher 提供了一個新的判斷方法(很完美)
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);
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);
我自己的實例:



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();
};
}
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();
};
}
幾點補充說明:
1、IE 支持 iframe 的onload 事件,不過是隱形的,需要通過 attachEvent 來注冊。
2、第二種方法比第一種方法更完美,因為 readystatechange 事件相對于 load 事件有一些潛在的問題。
名稱: ?4C.ESL | .↗Evon
口號: 遇到新問題?先要尋找一個方案乄而不是創(chuàng)造一個方案こ
mail: 聯(lián)系我