完美判断iframe是否加载完成

var iframe = document.createElement("iframe");
iframe.style.width = "265px";
iframe.style.height = "490px";
iframe.style.border = "none";
iframe.src = "http://cnblogs.com/walls";
        
if(iframe.attachEvent){
     //IE
     iframe.attachEvent("onload", function(){
         alert("loaded 1");
     });
}else{
     iframe.onload = function(){
         console.log("loaded 2");
     };
}

  

  1. IE 支持 iframe 的 onload 事件,不过是隐形的,需要通过 attachEvent 来注册。

摘自怪飞博客:http://www.planabc.net/2009/09/22/iframe_onload/

posted @ 2015-04-24 11:39  我是leon  阅读(642)  评论(0编辑  收藏  举报