Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  135] [ 1]  / answers: 1 / hits: 30691  / 7 Years ago, tue, february 21, 2017, 12:00:00

My CMS produces an img src=(unknown) if an image isn't provided in the database. I would like to use javascript when this occurs to change it to img src=/images/missing.png
As a complete JS noob I have tried several hacks but none seem to work... any ideas? (there is likely to be more than one image on the page if that makes any difference)


More From » image

 Answers
64

This should work for you, if you use onError event for handling missing image src



<img src=main_img.png onError=this.onerror=null;this.src='/images/missing.png'; />

[#58834] Monday, February 20, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;