I want to preload an image with javascript, the method below seems simple enough but how can I check if the image has preloaded? Thanks Preloading images with jQuery
Asked
Active
Viewed 1,218 times
2 Answers
3
I would suggest modifying the code to add on 'onerror' event handler to the img tags you are generating. and then handle any failures.

Glenn Ferrie
- 10,290
- 3
- 42
- 73
-
2You can do the same for the onload of the img as well: http://www.w3schools.com/jsref/event_onload.asp – endyourif Oct 17 '11 at 14:41
1
Make a log entry in your image's "onload" event.
myImage.onload = function(){
console.log("Image Loaded!");
}
If you're not familiar with chrome's developer tools or firefox's Firebug plugin, you should check them out. They make things like this a breeze.
Also, keep in mind that some browsers require the image.src attribute to be defined after the .onload event.

Daniel Szabo
- 7,181
- 6
- 48
- 65