i have to display auto-generated images from a folder in html.
how can i check if file exist in javascript/jquery so i can do a for-loop and display them all. they will be numbered 1.jpg, 2.jpg and so on.
i have to display auto-generated images from a folder in html.
how can i check if file exist in javascript/jquery so i can do a for-loop and display them all. they will be numbered 1.jpg, 2.jpg and so on.
You can probably fire a request and check the HTTP status code (404 for not existing ;))
Check this solution to the same question: http://stackoverflow.com/questions/197228/how-to-check-if-a-file-exists-in-javascript
If You don't like the ajax and checking http status method, there is a HTML-DOM way to do that.
if You put a new img node and add onload - it will fire only when/if image loads.
in jQuery:
var there=$('get where You want to put it');
$('<img />').attr('src',image_link).bind('load',function(){
do whatever You need to do if image loads
}).appendTo(there);
and it starts the function with "do whatever" after image loads.
cheers;)
I think you can use the onerror event of the img tag.
It will be triggered if the img is not loaded properly.
Within this event you could remove this(these) img and stop the loop.
Are you talking about client or server side javascript?
:->