no image attribute

Discussion in 'HTML & Website Design' started by easywab, Apr 23, 2008.

  1. #1
    Hi,

    When we ise <img src="imagename.gif" >

    If that image does not exist, can't we give alternative "noimage.gif" ?
    How do we do that in HTML?

    Pls. help...

    Thanks..
     
    easywab, Apr 23, 2008 IP
  2. MeetHere

    MeetHere Prominent Member

    Messages:
    15,399
    Likes Received:
    994
    Best Answers:
    0
    Trophy Points:
    330
    #2
    you can use alt text code
    alt="yourtext"
     
    MeetHere, Apr 23, 2008 IP
  3. easywab

    easywab Peon

    Messages:
    262
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi MeetHere,
    Thanks for your quick reply.
    But I need to put default image ( "noimage.gif ") if the original image does not exist... not the text ...
    Can anyone do that?
     
    easywab, Apr 23, 2008 IP
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    Just try javascript:

    
    <img src="image.png" alt="An Image" onerror="this.src='noimage.gif' />
    
    Code (markup):
    No idea if that will work.
     
    blueparukia, Apr 23, 2008 IP
  5. easywab

    easywab Peon

    Messages:
    262
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hi blueparukia,
    It's working ... But only in IE, Is there a work around for firefox ?
     
    easywab, Apr 24, 2008 IP
  6. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hmm, if you know the size of the images (meaning, if they are all the same) you COULD maybe have a background image always there in the CSS (of the element which contains the img tag)... IF there's an image, it simply covers the background image up. If there's not an image, then of course, people can just see the background one by default.

    I used this trick once, works well, but only when the possble covering-up images are bigger than the default, and can be positioned exactly.
     
    Stomme poes, Apr 24, 2008 IP