Analysis of the OnLoad method of IE iframe summary _javascript skills

Source: Internet
Author: User
The perfect way to judge if an IFRAME is loaded
IE support the onload incident of IFrame, but is invisible, need to register through attachevent.
The second method is more perfect than the first method (using ReadyStateChange judgment) because there are some potential problems with the ReadyStateChange event relative to the Load event.

The feeling here is not completely accurate, beginning to cause me a lot of trouble. See its code to understand, the real meaning of IE in the creation of a new IFRAME when the OnLoad method needs to use the attachevent to bind, and the original IFrame of the OnLoad method, you can directly bind.

Say a little messy, everyone look at the code, a look will know:

Copy Code code as follows:

<iframe id= ' Google ' ></iframe>
<script type= ' Text/javascript ' >
document.getElementById (' Google '). src= ' http://jb51.net/';
document.getElementById (' Google '). onload = function () {
Alert (' I am Google frame, now loaded ');
}
</script>

Here, also referred to the original text of the "Judge whether the completion of the perfect method of iframe" excerpt from this
Copy Code code as follows:

var iframe = document.createelement ("iframe");
IFRAME.SRC = "Http://www.jb51.net";

if (iframe.attachevent) {
Iframe.attachevent ("onload", function () {
Alert ("Local iframe are now loaded.");
});
} else {
Iframe.onload = function () {
Alert ("Local iframe are now loaded.");
};
}

Document.body.appendChild (IFRAME);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.