Copy codeThe Code is as follows:
Var iframe = document. createElement ("iframe ");
Iframe. src = "http://www.jb51.net ";
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 ):
Copy codeThe Code is as follows:
Var iframe = document. createElement ("iframe ");
Iframe. src = "http://www.jb51.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.