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

N

Nick

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....
 
E

Erwin Moller

Nick said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top