4

I want to show default image describing that image not found when one of the images in page is not found .

How to do it ?

RASKOLNIKOV
  • 732
  • 2
  • 9
  • 20
  • I doubt you can do that with means of html alone. That replacement image for "image not found" is something browser specific, implemented in the browser software of configuration. That (usually) is out of your hands. I'd say you have to use javascript for this, probably the most straight forward approach is to react on the event of the failed loading... – arkascha May 25 '15 at 14:45
  • hmm so I have answered question .Happy to teach you new thing. – RASKOLNIKOV May 25 '15 at 14:47
  • Try using the javascript event "onerror". Check this answer: http://stackoverflow.com/questions/7995080/html-if-image-is-not-found – edornd May 25 '15 at 14:48
  • 2
    @RASKOLNIKOV Hm, wonder when you realize yourself... Apart from that: why is this a new thing? You do _exactly_ what I suggested above. – arkascha May 25 '15 at 14:48
  • @RASKOLNIKOV Ah, now you realized :-) you see, what you do in your answer _is_ using javascript. That is _not_ a pure html solution. Just as I wrote above. You just embed your script into the html tag which works in some cases, though not in all, that depends on the security model of the page. (Oh, I just see it wasn't even you how realized... Someone else fixed your answer for you :-) ) – arkascha May 25 '15 at 14:57

1 Answers1

11

Think that you want to show in body default.jpg but this image not exist in application or in server.You want to show meaningful image to user describing that image not found.You want to show ImageNotFound.jpg to user

This is a solution:

<img src="default.jpg" onerror="this.src='ImageNotFound.jpg'" />
cHao
  • 84,970
  • 20
  • 145
  • 172
RASKOLNIKOV
  • 732
  • 2
  • 9
  • 20