javascript无法触发image.onerror处理程序

时间:2012-09-26 17:03:04

标签: image triggers handler onerror

不知何故,我无法触发onerror事件或让onerror中的代码工作。此代码尝试收集数组中的图像序列。我正在使用onerror事件来标记序列的结束,从而终止循环。

    //definition of Slide object
function Slide(inpImage, imgCaption) {
    this.inpImage = inpImage;
    this.imgCaption = imgCaption;
}

window.onload = function() {
        var defaultImage = img_slide.src; //This is a default file
        //basically getting the file path and name of next image in the sequence
        var nextImage = f_nextFile(f_path(img_slide.src),f_serial(img_slide.src)); 
        //An array object which stores Slide Objects
        arr_slides.push(new Slide(img_slide,img_slide.src)); 
        while (defaultImage != nextImage){ //code to populate arr_slides array
            var imgObj = new Image();
            imgObj.src = nextImage;
            arr_slides.push(new Slide(imgObj,nextImage));
            //get the next image in the sequence of images
            nextImage = f_nextFile(f_path(nextImage),f_serial(nextImage));
            testImage = function(nextImage,defaultImage){
                            var tester=new Image();
                            tester.onerror = function () {
                                                nextImage = defaultImage;
                                            };
                            tester.onload = function () {
                                                //do nothing
                                            };
                            var loadNext = function() {
                                                tester.src=nextImage;
                                           };
                            loadNext(); 
            };
            testImage(nextImage,defaultImage);
        }
        alert("The number of images in array : " + arr_slides.length);
     };

0 个答案:

没有答案