The perfect way to determine whether the iframe is loaded
IE supports the onload event of iframe, but it is invisible and needs to be registered through attachEvent.
The second method is more perfect than the first method (using readystatechange to judge), because the readystatechange event has some potential problems compared to the load event.
I feel like what I said here is not completely accurate, and it started to cause me a lot of trouble. Only after looking at the code do we understand that in a true sense, IE's onload method when creating a new iframe needs to be bound using attachEvent, while the onload method of the existing iframe can be bound directly.
It’s a bit confusing. You can read the code and you will know at a glance:
Here, we also excerpt the original article mentioned in the original article "The perfect way to determine whether the iframe is loaded."
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);
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn