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

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

iframe.src = "http://www.baidu.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);

你可能感兴趣的:(iframe)