Workaround for invalid image object onload in IE browser

Source: Internet
Author: User

As a web designer, in order to enhance the user experience on the Web page display, it is often used to load the display state method of the image, which naturally requires the OnLoad event of the image object. After the development in Firefox browser, but in the IE browser debugging can not be called. Whether the latest version of IE8 or the older versions of IE7 and IE6 are invalid, the initial code is simplified as follows:

var New  = "Test.gif"function() {    alert (this. src);     // other      };

A simple look after the seemingly this piece of code is not a problem, but IE is not able to run normally. No matter how testing, IE will not pay attention to, but still found a solution, the principle is as follows:
When the image is downloaded, the browser caches the picture and loads the image again from the buffer.
So if the image is already in the buffer, is not the image from the buffers to trigger the onload event?
Test......

var New  function() {    alert (this. src);     // other      = "Test.gif";

Test success!

Conclusion: The onload should be written in front of SRC, first tell the browser how to handle the picture after loading, and then let it load the picture. So, instead of IE, the OnLoad event is not triggered, but because the buffer is loaded too fast, it has been loaded without telling it what to do when it is loaded. Conversely, Firefox is significantly more intelligent, after adding the onload event, the Firefox browser will detect whether the buffer already has this picture, some words directly triggered this event!

Article from: http://www.iefans.net/ie-image-duixiang-onload/

Workaround for invalid image object onload in IE browser

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.