SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Image default

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image default

    Hey guys and gals,

    I'm not sure if this is the right place for this, so please do not hesitate to tell me if it is not.



    I would like to be able to specify a default image to load if the selected image path does not exist.


    For example:

    I specify "http://mysite.com/images/test.jpg" but that image does not exist.

    Instead of showing a broken image, it shows "http://mysite.com/images/image404.jpg".

    Is this possible? If so, how? I was thinking in my .htaccess or maybe my 404 page.




    Thanks in advance.

  2. #2
    Resident curmudgeon bronze trophy gary.turner's Avatar
    Join Date
    Jan 2009
    Location
    Dallas
    Posts
    990
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the object element.
    Code:
      <p><object type="image/gif"
              data="test1.gif">
        <img src="test2.gif"
           alt=""
           height="50"
           width="30" />
      </object></p>
    This may or may not work in various versions of IE.

    cheers,

    gary
    Anyone can build a usable website. It takes a graphic
    designer to make it slow, confusing, and painful to use.

    Simple minded html & css demos and tutorials

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gary,

    Thanks alot for the help!


    From my testing, it seems that "test1" is the image it trys to load and "test2" is what it trys to replace it with if "test1" is missing. Is this correct?




    Also, does anyone else have any other suggestions?


    Thanks in advance!

  4. #4
    Resident curmudgeon bronze trophy gary.turner's Avatar
    Join Date
    Jan 2009
    Location
    Dallas
    Posts
    990
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ttpyro View Post
    Gary,

    Thanks alot for the help!


    From my testing, it seems that "test1" is the image it trys to load and "test2" is what it trys to replace it with if "test1" is missing. Is this correct?
    Yep, pretty much. IFRAME will work the same way, but iframe has its own mess to clean up.

    cheers,

    gary
    Anyone can build a usable website. It takes a graphic
    designer to make it slow, confusing, and painful to use.

    Simple minded html & css demos and tutorials


Bookmarks

Posting Permissions

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