Reputation: 1131
I would like to set default image from broken image. I know the answer would be to change url of image on error, however thats not what i want.
I have made a template editor in which user changes source to dynamic url. At that moment the image looks broken but later when he send it, it will be autofilled.
when the image src is changed to dynamic url broken image is shown. I would like to retain the src of the image but still show some good background image istead of the default broken image.
example:
<img src="dynamic.src"></img>
In this case the src is not found., if i write a javscript to change the src onerrr to some static img then i will loose the link which the user set, i.e "dynamic.src" in this case.
Any solution will be of great help
Upvotes: 0
Views: 853
Reputation: 1849
Most browsers make nonexistent images transparent. Therefore, you can add a background-image
to the image element. If the image exists, it will cover up the background image, but nonexistent images will be transparent, letting the background-image show.
Upvotes: 1