Forum Moderators: phranque

Message Too Old, No Replies

Broken image links (nasty red x's)

Test for them and display something else?

         

lazycat

4:14 pm on Apr 16, 2005 (gmt 0)

10+ Year Member



Is there an easy (or not so easy) way to test whether an external image you are linking to is broken (been moved etc.) and to display something else (like a default "no image available" graphic) rather than those nasty red x's IE puts there for unfound images?

Seems like it should be easy to do but so far I'm drawing a blank. Any help would be hugely appreciated. :)

jomaxx

4:51 pm on Apr 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, link to your own images on your own server.

lazycat

5:24 pm on Apr 16, 2005 (gmt 0)

10+ Year Member



Thanks for the help. FWIW I'm using datafeeds provided by other companies who prefer me to link to the images on their servers.

I just figured something out using getimagesize() in php anyway, probably not the best solution but it seems to work.

KingMacro

5:30 pm on Apr 16, 2005 (gmt 0)

10+ Year Member



<img src="http://www.blah.com/blah/blah.gif" onerror="this.src='error.gif';">

when the image fails to load it will run the javascript in the onerror, which will change the image location :-D

jomaxx

11:37 pm on Apr 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry for the snarky reply, but in the vast majority of cases it's a very poor practice.

Anyway, the PHP solution requires your own server to access the third party images before generating the HTML source, which seems slow and wasteful. The JS solution looks like the way to go. You might need to adjust the image.height and image.width parameters as well.