...

View Full Version : Resolved Check if image file exists on remote server



ironj221
09-20-2009, 11:31 AM
What I'm Doing
I am checking to see if http://www.example.com/favicon.ico exists. If it does not, I want to display a default image.

The Problem
Yes, I have Google'd many solutions to check if an image path is valid on a remote server. However, my problem is that I am checking around 10-20 sites every time my site loads, which makes it way too slow.

Solutions?
Does anyone have ideas for a solution that would make it very quick, possibly something locally that checks?

Help is appreciated.

MattF
09-20-2009, 12:02 PM
Do a background image in the CSS for the favicon container. If the remote image doesn't exist, your background image will be visible.

ironj221
09-20-2009, 12:06 PM
Do a background image in the CSS for the favicon container. If the remote image doesn't exist, your background image will be visible.

Hey I actually already thought of that, but the problem is...many favicons are transparent. :(

ironj221
09-21-2009, 01:47 AM
Finally figured out that you can add an attribute called onerror to the img tag. This will perform some javascript when an image does not exist. Very cool feature that seems to work on all browsers that I have never heard of before.


onerror="dwkwa_nophoto(this)"



function dwkwa_nophoto(object){
object.src = "/images/none.png";
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum