56 users online (1 members and 55 guests)  


  Results 1 to 6 of 6

Related

  1. Replies: 3
  2. please test for me...help!    Forum: Web Hosting Forum
    Replies: 8
  3. Replies: 14
  1. #1
    woodknut's Avatar
    Disabled

    Status
    Offline
    Join Date
    Dec 2003
    Posts
    32

    Question How to test for existance of image?

    I am working on a directory style page that will include "thumbshots" from www.thumbshots.org beside the directory links.

    The script that they provide looks like this:
    <img src="http://open.thumbshots.org/image.pxf?url=[LINK]" border="0" onload="if (this.width>50) this.border=1" alt="Preview by Thumbshots">

    I am placing this image tag within a hyperlink tag such that the image becomes a clickable link.
    The script downloads an image, if it exists; otherwise it returns a "1x1 transparent pixel".

    What I would like to do is display a different image (with different alt, border, etc) if the thumbshot image is unavailable. How do I go about this? An onload script seems the way to go but I'm not sure how to test for a "1x1 transparent pixel".

    W.

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    No need, JavaScript cannot test for files but it CAN detect an error loading the image. Try -
    Code:
    <img src="firstImage.gif" onError="this.src='otherImage.gif';">
    MAKE SURE "otherImage.gif" exists or else the browser will go into an infinite loop!
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    woodknut's Avatar
    Disabled

    Status
    Offline
    Join Date
    Dec 2003
    Posts
    32
    Thanks. I've tried onerror and onload with mixed results....and at this point its not functioning at all. During testing I've also seen the infinite loop and "stack overflow". oh boy.

    Here's the code snippet:
    <a href="http://www.testme.com/" target=_blank class="link"><img align="left" src="http://open.thumbshots.org/image.pxf?url=http://www.testme.com/" border="0" alt="Preview by Thumbshots" width="120" height="90" onerror="this.src='../images/nopicture.gif'; this.alt='No Picture Available';"></a>

    If the script doesn't find an image it is supposed to return a 1x1 pixel. Isn't this then stored in the <IMG src.. ? I've tried testing for this.width==1 and it doesn't work.

    I'm using IE 6.0 btw.

    W.

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Ah. Your using some kind of dynamic image (.pxf)
    You would be better off moving the testing for the file into the .pxf, its a lot more reliable.

    I am assuming .pxf is some kind of scripting, I have never heard of it.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    woodknut's Avatar
    Disabled

    Status
    Offline
    Join Date
    Dec 2003
    Posts
    32
    Thanks Dean.
    Yes its some kind of script provided by Thumbshots.org (i.e. its not mine).
    I'll find some work around.

    W.

  6. #6
    interfx's Avatar
    New User

    Status
    Offline
    Join Date
    Aug 2004
    Posts
    1
    I am having the same issue, did you ever figure it out?

    I tried this

    <img src="http://open.thumbshots.org/image.pxf?url=[URL]" border="1" align="left" alt="Previews by Thumbshots" onload="if (this.width<50) {this.src='/images/No_ThumbShot.gif'; this.width='120'; this.height='90'}"></a>

    But got stack overflow by zero in IE6... Works fine in mozilla - but am styill try to figure out a solution...


    I tried the suggestion above, but never got it working

    Thanks for ideas...

    interFX



Tags for this Thread