我能想到的有以下几种方式:

 

方法一、jQuery load()

 

Js代码  收藏代码
  1. var frm = document.getElementById('myiframe');  
  2. $(frm).load(function(){                             //  等iframe加载完毕  
  3. dosomething();  
  4. });  

 

方法二、onreadystatechange

 

Js代码  收藏代码
  1. var iframe = document.createElement("myiframe");  
  2. iframe.src = "http://www.baidu.com";  
  3. if (!/*@cc_on!@*/0) { //如果不是IE,IE的条件注释  
  4.     iframe.onload = function(){     
  5.         alert("Local iframe is now loaded.");  
  6.     };  
  7. else {  
  8.     iframe.onreadystatechange = function(){ // IE下的节点都有onreadystatechange这个事件  
  9.         if (iframe.readyState == "complete"){  
  10.             alert("Local iframe is now loaded.");  
  11.         }  
  12.     };  
  13. }  
  14. document.body.appendChild(iframe);  

 

方法三、attachEvent

Js代码  收藏代码
  1. var iframe = document.createElement("iframe");  
  2. iframe.src = "http://www.baidu.com";  
  3.   
  4. if (iframe.attachEvent){  
  5.     iframe.attachEvent("onload"function(){ // IE  
  6.         alert("Local iframe is now loaded.");  
  7.     });  
  8. else {  
  9.     iframe.onload = function(){ // 非IE  
  10.         alert("Local iframe is now loaded.");  
  11.     };  
  12. }  
  13.   
  14. document.body.appendChild(iframe);  
posted on 2014-03-23 22:02  GC2013  阅读(34331)  评论(2编辑  收藏  举报