Click to See Complete Forum and Search --> : Image errors


Staticreator
01-14-2003, 04:00 PM
I have a program that moniters an image to wait for it to download, it uses the onError property to detect if the download failed. Only problem is, some sites have 404 pages that appear if a link is wrong. When this happens, my program does nothing because nothing changes, the onError function isn't triggered, and none of the image's propertys appear to change. How can I detect this? Also, the program is IE only, so I don't need to worry about compatibility problems.

Staticreator
01-15-2003, 03:06 AM
Really? Most sites have them, even for images. I can't give you the link to the actual images I was using but here: http://www.yahoo.com/idontexist.gif

Webskater
01-15-2003, 03:25 AM
That yahgo link is a request for a page called www.yahoo.com/idontexist.gif and it returns the 404 error because the page does not exist. Every server that I've come across puts an icon on the page to show it could not find an image - it does not produce a 404 error. I think there is a bit of confusion here.

Staticreator
01-15-2003, 06:08 AM
Maybe I should restate my question, how do you detect if an img tag is linked to a html page and not to an actual image?

gil davis
01-15-2003, 06:51 AM
Originally posted by Staticreator
Maybe I should restate my question, how do you detect if an img tag is linked to a html page and not to an actual image?IMHO, that makes less sense to me than your original post.Originally posted by Webskater
Every server that I've come across puts an icon on the page to show it could not find an imageThe browser puts the broken image icon there, not the server.

This syntax will detect an image error:

<img src="..." onerror="[some script function]" ...>

For example:

<img src="http://www.yahoo.com/idontexist.gif" onerror="alert('no image')">

The alert will fire after the server informs the client that the requested image is not there.

The real question is why would you code a page with an image and not put the image on the server? What are you really trying to do?

Staticreator
01-15-2003, 02:21 PM
Ack, I fixed the problem, but it was due to other things, not anything I said, sorry I assumed it had to do with the 404.

Turns out it was really had to do with the onError in the image triggering before the script was finished working, I've been working with Javascript for a while and I've never encountered anything like that, but everythings fine now. Thanks for you help.

By the way, I was about to come here for another problem but I fixed that too, turns out theres 25 hours on the day we switch to Daylight Savings Time, who knew? :P