1

There are 0.png, 1.png, 2.png, ... in folder images. How to load all them. Number of the images unknown.

} while(!img[numOfImages].onerror);

alert("numOfImages = " + numOfImages);

var	
  numOfImages = 0;
  img = [];	

do{
	img[numOfImages] = new Image();
	img[numOfImages].src = "images/" + numOfImages + ".png";
	numOfImages++;
} while(!img[numOfImages].onerror);
alert("numOfImages= " + numOfImages);

1 Answer 1

1

Code:

    var dir = "Src/themes/base/images/";
var fileextension = ".png";
$.ajax({
    //This will retrieve the contents of the folder if the folder is configured as 'browsable'
    url: dir,
    success: function (data) {
        //List all .png file names in the page
        $(data).find("a:contains(" + fileextension + ")").each(function () {
            var filename = this.href.replace(window.location.host, "").replace("http://", "");
            $("body").append("<img src='" + dir + filename + "'>");
        });
    }
});

This will load all the image .png present in a folder, care that this code use jquery.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.