Tuesday 23 April 2013

Change not found image by onerror event

We can change image Src when image is not found or image is not loaded by using onerror event of javascript. For Example

demo

img src="any url" onerror="changeimage(this)"

function changeimage(id) {
    id.src = "http://3.bp.blogspot.com/-1jy-2M0NQ3Y/UXaFNs3oUZI/AAAAAAAAAaM/GtBpwYxkf0s/s1600/NoImage.jpg";
}
when image is not found then automatically this function change image src by noimage.jpg which is default image.

No comments :

Post a Comment