当前位置: 首页 > 图文教程 > 网络编程 > Javascript > IE iframe的onload方法分析小结

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 IE iframe的onload方法分析小结


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 416 ::
收藏到网摘: n/a

在判断 iframe 是否加载完成的完美方法一文中,怿飞最后有如下两点补充。 判断iframe是否加载完成的完美方法
IE 支持 iframe 的 onload 事件,不过是隐形的,需要通过 attachEvent 来注册。
第二种方法比第一种方法更完美(采用readystatechange判断),因为 readystatechange 事件相对于 load 事件有一些潜在的问题。
这里感觉说的并不是完全准确,开始给我造成了很大的困扰。看其代码才明白,真正意义上来讲IE在创建一个新的iframe时的onload方法需要使用attachEvent来绑定,而原来就存在的iframe的onload方法,则可以直接绑定。
说的有些乱,大家看代码,一看便知:
复制代码 代码如下:

<iframe id='google'></iframe>
<script type='text/javascript'>
document.getElementById('google').src='http://ruanchen.com/'google').onload = function(){
alert ('I am google frame, now loaded');
}
</script>

在这里,也把原文提到的”判断 iframe 是否加载完成的完美方法”原文摘录至此
复制代码 代码如下:

var iframe = document.createElement("iframe");
iframe.src = "http://www.ruanchen.com";
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);