Sunday, November 18, 2007

Image Onload Problems

I've written a few slide shows, and one of the things that bugs me is that the image.onload function seems to not be supported very well on numerous browsers. Here might be the culprit.



// evil:
var image = new Image();
image.src = 'image.jpg';
image.onload = function() {
// sometimes called
alert('image loaded');
};

// good:
var image = new Image();
image.onload = function() {
// always called
alert('image loaded');
};
image.src = 'image.jpg';


To be honest, I'm not sure if this works or not, especially in Safari 1.x and Opera, but I'll give it a shot. The only other work around I've seen is pretty complicated.

Thanks to http://www.thefutureoftheweb.com/blog/image-onload-isnt-being-called for posting this.

No comments: