How to check if images are being preloaded?
I wa开发者_StackOverflownt 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
I would suggest modifying the code to add on 'onerror' event handler to the img tags you are generating. and then handle any failures.
http://www.w3schools.com/jsref/event_onerror.asp
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.
精彩评论