Possible Duplicate:
jQuery or JavaScript: Determine when image finished loading
The problem is known, but I can’t find any simple solution:
var img = new Image();
img.onLoad = function() {
console.log("load"); // this event doesn't fire
};
img.src = "img/domino/21.png";
console.log(img.complete); // false
setTimeout(function() {
console.log(img.complete); // sometimes true, sometimes false
}, 10);
I was looking for an implementation of onComplete event, but I can’t find anything. Would you help?
The proper spelling of the event handler property is all lowercase
.onload, not.onLoad.Javascript is case sensitive so you MUST use the proper case for all object properties.
The alternatives besides
.onloadare to use:or (in older versions of IE):
If you’re only using one event handler and you aren’t using a cross platform library that already abstracts event handlers for you, then using
.onloadis the simplest.And, here’s a simple cross browser way to add event handlers: