我目前正在使用setTimeout
和onLoad
按顺序加载几张图像。基本上当图像加载完成时,触发onLoad
,通过setTimeout
调用启动另一个图像加载。不幸的是,如果图像加载由于某种原因(如后续的ajax
调用)而中断,则onload永远不会被调用,并且任何要加载的图像都不会被加载。有没有什么方法可以检测到这种情况?我试图挂钩到onError
和onAbort
(在图像标签上),这些都不被称为。在Javascript中检测图像负载取消
queuePhotos: function(options)
{
this.init();
this.photo_urls = options.photo_urls;
this.photo_size = options.size
this.max_width = options['max_width'];
this.max_height = options['max_height'];
this.containers = options['containers'];
yd = YAHOO.util.Dom;
photo_tags = yd.getElementsByClassName('image_stub', 'div');
for(i in photo_tags)
{
//create new image
photo = new Image();
this.queue.push({ tag: photo_tags[i], photo: photo });
}
setTimeout(photoLoader.prepareNextPhoto, 1);
},
prepareNextPhoto: function()
{
photo_tag_and_image = photoLoader.queue.shift();
if(photo_tag_and_image)
{
YAHOO.util.Event.addListener(photo_tag_and_image.photo, "load", photoLoader.appendPhoto, photo_tag_and_image, photoLoader);
photo_tag_and_image.photo.src = photoLoader.photo_urls[photo_tag_and_image.tag.id];
}
},
的“别的东西”可能是,如果在AJAX调用设置新的innerHTML包含加载图像元素,或者其母公司上。 – 2009-10-26 23:25:44