HTML if image is not found
I have an image in a HTML page:
<img src="smiley.gif" alt="Smiley face" width="32" height="32" />
If the image is not found on the server it shows an ugly blank square.
I want to make it so that if an image is not found it will display nothing or some other default image that I know is definitely on the server.
How can this be done?
The best way to solve your problem:
<img id="currentPhoto" src="SomeImage.jpg" onerror="this.onerror=null; this.src='Default.jpg'" alt="" width="100" height="120">
onerror
is a good thing for you :)
Just change the image file name and try yourself.
Well you can try this.
<object data="URL_to_preferred_image.png" type="image/png">
<img src="URL_to_fallback_image.png" />
</object>
this worked for me. let me know about you.