tags:

views:

69

answers:

1

I use the function below to update a webcam image. Now I would like to change the function so that it is not fired when the webcam image is not available (error function). Someone plz help me?

$("img#activecam").error(function () {
    // 
})

setInterval("updatecam()", 16000);  


function updatecam() {  
    $('#activecam').attr('src', '<?php echo $image; ?>&time='+Date()); 
}
A: 

You could perhaps make use of the jQuery Head plugin to perform an XmlHttpRequest HEAD on your image's URL, then check for a 200 OK in the response. You could then assume the image would be OK to display, or you could choose to display an alternate image if not.

It should be noted that, unfortunately, this does have the overhead of two HTTP connections (first for the HEAD and the second for the image src) instead of just one. However, if you're only updating this every 16 seconds, this shouldn't be noticeable.

Good luck!
-Mike

Funka