A lot of times non existing images come up on webpages that you are unaware of. Here is an easy way to handle non existing images.

We can use error event on img tag to verify whether images exist or not.

HTML & Script
<img src="pic-1,jpg" alt="" id="example" />
<script type="text/javascript">
    $(document).ready(function () {
        $("#example").bind("error", function () {
            if (confirm("Unable to load image, would you like to load different image?")) {
                $("#example").attr("src", 'pic-1.jpg');
            }
        });
    });
</script>
If you have any questions regarding photozoom please ask in the comment box below. I will be happy to help you.
Subscribe for our monthly newsletter for updated articles and useful code scripts.

Share It

comments powered by Disqus