When we show a profile image we get image path from database and show that image as a profile image. But if image not found or image path is not correct then we see a broken image. So we add a conditions there to show a defualt image. But if we use onError event there is no need to add a conditions script. onError event will fire when image not found or image format is not correct. For example
There was an error in img tag when no image source found. I used this
< img src="path/myimage.png" onerror="this.src='path/defualtImage.png'" />
and it works fine for me. Try it
0 Comment(s)