返回首页·设为首页·加入收藏·WAP·RSS
资讯业内人物评论
软件WordExcelWPS
安全杀毒入侵政策
硬件CPU内存硬盘
黑客漏洞入侵木马
认证微软思科华为
脚本ASPJSP
网络交换路由
设计PSCorelDraw
编程JavaVCVB
制图AutoCadCAXA
协议TCPIPIPv6

您现在的位置:蛤蟆网>> 脚本>> JavaScript>>正文内容

判断 iframe 是否加载完成的完美方法

作者:蛤蟆采编组 来源:蛤蟆网 发布时间:2010年07月20日 点击数:
     今天正好需要判断iframe加载完成 正好找到怿飞同学的这篇文章 方法很完美

var iframe = document.createElement("iframe");

iframe.src = "http://www.xker.com";

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》的评论中 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);

几点补充说明:

IE 支持 iframe 的 onload 事件,不过是隐形的,需要通过 attachEvent 来注册。
第二种方法比第一种方法更完美,因为 readystatechange 事件相对于 load 事件有一些潜在的问题。


共1页 您在第1页 首页 上一页 1 下一页 尾页 跳转到页 本页共有1216个字符
  • 没有任何带图片的信息!
  • 联系我们 | 网站留言 | 友情链接 | 版权声明 | 网站公告 | 快速导航 | 会员登陆
    CopyRight© 2004-2010 www.HaMaIt.cn All Rights Reserved
    Email:WebMaster@HaMaIt.cn QQ:308164407 辽ICP备08101943号