Using javascript is there a way to tell if a resource is available on the server? For instance I have images 1.jpg - 5.jpg loaded into the html page. I\'d like to call a Jav
You can use the basic way image preloaders work to test if an image exists.
function checkImage(imageSrc, good, bad) { var img = new Image(); img.onload = good; img.onerror = bad; img.src = imageSrc; } checkImage("foo.gif", function(){ alert("good"); }, function(){ alert("bad"); } );
JSFiddle