In the OnLoad
handler of my webpage I'm trying to check if all images have loaded correctly.
I'm iterating over all <img>
tags and check them with my isImageLoaded()
function. Unfortunately my function only works with Firefox and IE up to version 8.
Any suggestions how I can get it to work in IE 9 and 10?
function isImageLoaded(img) {
// check for IE
if (!img.complete) {
return false;
}
// check for Firefox
if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
return false;
}
// assume it's ok
return true;
}
Update: It turns out the main culprit is that OnLoad can be fired before all image are loaded by IE9+. What would be a better trigger to check the images in the page ? I would prefer to check them all at once and not with individual OnLoad / OnError handlers.