Home
HTML Image Onerror
Blog Date 18 February 2022
The Code
<img src="priimg/DB-Solus-Loo.jpg" onerror="this.src='priimg/Dead.jpg'" />
The Explanation
99% of the time there's no real excuse for a missing image on your website. However the world is not a perfect place. As such if you can remember (or be bothered) you can set an image to default to something if there's a problem with the image.
The most important thing to note is be sure you error image DOES EXIST! Otherwise Javascript goes into an endless loop -
"Try to get picture, fail, instruction on fail is try to get picture, fail, instruction on fail is try to get picture, fail........"
Reader's Comments
Name
Comment
Add a RELEVANT link (not required)
Upload an image (not required)
Uploading...
Home