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

Post Your Comment Posts/Links Rules

Name

Comment

Add a RELEVANT link (not required)

Upload an image (not required)

No uploaded image
Real person number
Please enter the above number below




Home
Admin Ren's Biking Blog