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

Discussion in 'Javascript' started by Nick, Mar 4, 2004.

  1. Nick

    Nick Guest

    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....
     
    Nick, Mar 4, 2004
    #1
    1. Advertising

  2. Nick

    Erwin Moller Guest

    Re: How to change the pic to a "show error" image when loading images failed?

    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
     
    Erwin Moller, Mar 4, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dixon
    Replies:
    4
    Views:
    574
    Piotr Dobrowolski
    Jan 30, 2006
  2. Onur Bozkurt
    Replies:
    0
    Views:
    404
    Onur Bozkurt
    Jun 30, 2003
  3. Replies:
    4
    Views:
    345
  4. edfialk
    Replies:
    0
    Views:
    214
    edfialk
    May 10, 2007
  5. voodoodan

    Text Change upon Pic Click

    voodoodan, Jul 3, 2007, in forum: Javascript
    Replies:
    1
    Views:
    88
    Erwin Moller
    Jul 4, 2007
Loading...

Share This Page