IE Bug: Onload Function in Animated Image
Issue with JavaScript Onload Function
In beginning of this year after successfull learning of new IE7 I’ve came face to face to unexplained behaviour of Internet Explorer and only now I can say what this behaviour also exists in IE6 too. (If anybody from you can test in on IE5 and comment here it would be very nice and useful). Essence in the following. When I use onload function for image its must called when function have loaded, but if I use animated image then function called with any new frame loaded. See this example of IE Bug with onload function (make sure what you are using Internet Explorer). For animated images it just loops and never complete. You can make benchmark of IE bug by yourself using following code.
<script type="text/javascript">
function _print(e) {
document.body.appendChild(document.createTextNode(e));
document.body.appendChild(document.createElement('BR'));
}
</script>
<div><img src="images/glitter_text.gif" alt="Animated Glitter Text"
onload="_print('loaded at ' + (new Date()))" /></div>
Have to say what in any other browser this code working well.
IE Bug Fix
Existence of problem had cause me to find the solution to fix this animation bug. My solution (bug fix) in using a bibb after first loading (see sample below). See example of Bug Fix of onload Animated Image (make sure what you are using Internet Explorer).
<script type="text/javascript">
function _print(e) {
document.body.appendChild(document.createTextNode(e));
document.body.appendChild(document.createElement('BR'));
}
</script>
<div><img src="images/glitter_text.gif" alt="Animated Glitter Text"
onload="_print('loaded at ' + (new Date())); this.onload=null;" /></div>
Using of line this.onload=null; is important for right behaviour and fixing of bug.
Any your comments about this bug and its fix are very appreciated!
October 23rd, 2007 at 4:50 pm
[...] have problems with ads on my site jplay.info. After publication of article about IE Bug on http://jplay.info/ie-bug-onload-function-in-animated-image/ my site have shown only PSA ads. Today I’ve added atricle about social bookmarks [...]