Tuesday, December 10, 2013

Broken Image handling in jsp/html

Instead of showing a blank image, the best thing is to hide the img element itself from html page. 
This can be done using following script:-

<script>
// Hide img tag
$("img").error(function(){ $(this).hide(); });
</script>

In case you want to show a blank image jpg, this can be achieved using following script:

<script>
// Replace missing image $('img').error(function(){ $(this).attr('src', 'missing.jpg'); });
</script>






No comments:

Post a Comment