Today, I just need to judge that the iframe loading is complete. I just found out that the method for this article is perfect.
Var iframe = document. createElement ("iframe ");
Iframe. src = "http://www.bkjia.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 );
Recently, Christopher provided a new judgment method (perfect) in the comment on the document "Iframes, onload, and document. domain" in the document "Nicolas C. Zakas" Iframes, onload ):
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 );
Additional Notes:
IE supports iframe onload events, but they are invisible and need to be registered through attachEvent.
The second method is more perfect than the first method, because the readystatechange event has some potential problems compared with the load event.