Is it possible in JavaScript to have a loop that checks to see whether an image is available and then if it is, change the SRC of an img tag to match? The loop would have a counter so the first time it is run it would look for image1.png and the image2.png and so on.
I want it to load image1.png once it is avaliable, and then check to see if image2.png is avaliable, and as soon as it is, load it into the page, and then do the same with image3.png and so on.
I have tried using
function imageExists(image_url){
var http = new XMLHttpRequest();
http.open('HEAD', image_url, false);
http.send();
return http.status != 404;
}
from Check if image exists on server using JavaScript?, but I need the webpage to work locally on the computer, and this does not seem to work then.
Is there any way to achieve this?