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