Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    25
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Check if image file exists on remote server

    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.
    Last edited by ironj221; 09-21-2009 at 01:45 AM.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Do a background image in the CSS for the favicon container. If the remote image doesn't exist, your background image will be visible.

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    25
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    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.

  • #4
    New Coder
    Join Date
    May 2008
    Posts
    25
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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.

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •