我目前正在使用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