Site Navigation

Showing posts with label onload. Show all posts
Showing posts with label onload. Show all posts

Saturday, March 22, 2008

bug 279 - onload event for images might not happen

Issue: #279
Affects: IE6, IE7, Opera (ver?)

When you add an image to a page dynamically (via the DOM) and you set the .src attribute, if IE/Opera has it in the cache it is loaded instantly, thus if you set an event handler to catch the onload after setting the source, you're onload event may never fire.

Example:

<script type="text/javascript">
var myImg = document.getElementsByTagName('img')[0];
myImg.src = 'highlight.png';
myImg.onload = function(){
alert('image loaded!');
}
</script>



Known Workarounds: One. Move the event handler up to a position before the .src is declared.

Example Workaround Code:

<script type="text/javascript">
var myImg = document.getElementsByTagName('img')[0];
myImg.onload = function(){
alert('image loaded!');
}
//define src "after" the onload handler
myImg.src = 'highlight.png';
</script>



Related Issues: None.

Bug/Site Feedback |
Submit a bug

Sunday, November 11, 2007

bug 208 - onload event fires for every frame of an animated GIF

Issue: #208
Affects: IE5, IE5.5, IE6, IE7
Fixed In: IE8

The onload event can be attached to a window, frame or image element and will fire when the element has fully loaded. However in IE, if you attach this event to an animaged GIF image, it will fire for EVERY frame in the animation!

Example:

<img src="waiting.gif" onload="waitLoaded();"/>


If you load this in IE, with an animated GIF, it will continuously execute the waitLoaded() event handler until the user presses Escape/Stop.


Known Workarounds: One.
The only workaround for this, is to immediately nullify the event handler after it has fired the first time.

Example Workaround Code:

<img src="waiting.gif" onload="waitLoaded();this.onload=null;"/>



Related Issues: None.

Friday, November 9, 2007

bug 317 - onload doesn't work everywhere

Issue: #317
Affects: Firefox, IE6, IE7, Opera, Safari

According to the JavaScript documentation, the onload event can be handled for the body, iframe, img, frameset & object tags. However not all browsers obey this the same.

Supports iframe onload:
Firefox - Yes
IE6, IE7 - Yes
Opera - Yes

Safari - No

Supports object onload:
Firefox - No
IE6, IE7 - No
Opera - No
Safari - Yes

So, take this into consideration if you are planning to use object versus an iframe in your next project.


Known Workarounds: None.

Related Issues: None.