IE iframe的onload方法分析小結(jié)
更新時間:2010年01月07日 23:45:14 作者:
在判斷 iframe 是否加載完成的完美方法一文中,懌飛最后有如下兩點補充。
判斷iframe是否加載完成的完美方法
IE 支持 iframe 的 onload 事件,不過是隱形的,需要通過 attachEvent 來注冊。
第二種方法比第一種方法更完美(采用readystatechange判斷),因為 readystatechange 事件相對于 load 事件有一些潛在的問題。
這里感覺說的并不是完全準確,開始給我造成了很大的困擾。看其代碼才明白,真正意義上來講IE在創(chuàng)建一個新的iframe時的onload方法需要使用attachEvent來綁定,而原來就存在的iframe的onload方法,則可以直接綁定。
說的有些亂,大家看代碼,一看便知:
<iframe id='google'></iframe>
<script type='text/javascript'>
document.getElementById('google').src='http://jb51.net/';
document.getElementById('google').onload = function(){
alert ('I am google frame, now loaded');
}
</script>
在這里,也把原文提到的”判斷 iframe 是否加載完成的完美方法”原文摘錄至此
var iframe = document.createElement("iframe");
iframe.src = "http://www.dbjr.com.cn";
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);
IE 支持 iframe 的 onload 事件,不過是隱形的,需要通過 attachEvent 來注冊。
第二種方法比第一種方法更完美(采用readystatechange判斷),因為 readystatechange 事件相對于 load 事件有一些潛在的問題。
這里感覺說的并不是完全準確,開始給我造成了很大的困擾。看其代碼才明白,真正意義上來講IE在創(chuàng)建一個新的iframe時的onload方法需要使用attachEvent來綁定,而原來就存在的iframe的onload方法,則可以直接綁定。
說的有些亂,大家看代碼,一看便知:
復(fù)制代碼 代碼如下:
<iframe id='google'></iframe>
<script type='text/javascript'>
document.getElementById('google').src='http://jb51.net/';
document.getElementById('google').onload = function(){
alert ('I am google frame, now loaded');
}
</script>
在這里,也把原文提到的”判斷 iframe 是否加載完成的完美方法”原文摘錄至此
復(fù)制代碼 代碼如下:
var iframe = document.createElement("iframe");
iframe.src = "http://www.dbjr.com.cn";
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);
相關(guān)文章
JavaScript獲得當前網(wǎng)頁來源頁面(即上一頁)的方法
這篇文章主要介紹了JavaScript獲得當前網(wǎng)頁來源頁面(即上一頁)的方法,涉及javascript中document.referrer方法的使用技巧,需要的朋友可以參考下2015-04-04Extjs 點擊復(fù)選框在表格中增加相關(guān)信息行
這篇文章主要介紹了Extjs 點擊復(fù)選框在表格中增加相關(guān)信息行 的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07element-ui的回調(diào)函數(shù)Events的用法詳解
這篇文章主要介紹了element-ui的回調(diào)函數(shù)Events的用法,本文通過實例代碼給大家介紹了change回調(diào)函數(shù)的使用方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-10-10