469,903 Members | 1,620 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

How to change the pic to a "show error" image when loading imagesfailed?

How to change the pic to a "show error" image when loading images failed
- for example, no image file exists?

I tried to add the following statement in the onload event function:

if (!document.images.AImage.complete) { document.images.AImage.src =
"error.gif";); }

However, I found that a lot of images can be successfully loaded will
also be replaced with the "error.gif".

After remove above line, these exist images can be show successfully.
But I want to change the non-exist images src to the error.gif....
Jul 20 '05 #1
1 2110
Nick wrote:
How to change the pic to a "show error" image when loading images failed
- for example, no image file exists?

I tried to add the following statement in the onload event function:

if (!document.images.AImage.complete) { document.images.AImage.src =
"error.gif";); }

However, I found that a lot of images can be successfully loaded will
also be replaced with the "error.gif".

After remove above line, these exist images can be show successfully.
But I want to change the non-exist images src to the error.gif....


use the eventhandler named: onAbort() or onError() or both.

I think onError() it will do just that. :-)

<img src="nonexistant.gif" onError="alert('help me!');">

Regards,
Erwin Moller
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Greg Burns | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.