#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    2
    Rep Power
    0
    I want a link to target a picture in a small frame, but if the picture doesn't exist, i want the link to change... Can someone help me!!!! PLEASE

    ------------------
    pR|Mo
  2. #2
  3. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    I don't think there's any way for Javascript to check for the existence of a file.

    If you are able to use some server-side such as PHP or Perl, the answer is quite simple, as they provide methods of checking whether files exist.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    81
    Rep Power
    15
    JavaScript can check for the existance of the file, but it is server side. It must be included between the <server></server> tags.

    Then use File.exists() The File object only has two properties, constructor and prototype, but it has a myriad of methods. The 'exists' method is the one you're looking for.


    If never done this before, but it should work assuming the server has JavaScript installed. Else try VBScript or Perl as mentioned before.
  6. #4
  7. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Actually, I might have to eat my words. After browsing 'Pure Javascript' (SAMS Publishing) I found the following:

    There is a properties of the image object called 'complete'

    Also there is an 'onLoad' event and an 'onError' event.

    I think perhaps the simplest use would be
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><IMG name="myimage" src="yourfirstimage.jpg" onError="switchimage(identifier)">[/code]

    switchimage() would be the name of your Javascript function to switch the 'src' attribute to "myimage", and "identifier" would be the parameter you pass to your function, so you can use it on several different images on your page, if need be.

    (Bear in mind that I haven't had time to test any of this, but if you run into trouble, let me know, and I will try to help)

    rmarks: yes if server-side Javascript is installed you are correct. However, that requires either Netscape Enterprise Server, or IIS running ASP. Javascript is occasionally installed on other webservers, but that number is extremely low.


    [This message has been edited by rycamor (edited June 05, 2000).]
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    81
    Rep Power
    15
    I agree. I've always found it unfortunate that VBScript tends to be the default server side language while JavaScript is the default CLient Side language. Too bad they're not the same. But that's a philosophical arguement.

    Your solution is a good one. I completely forgot about the onError event.

    If a person does want to run server side script, I forgot to mention the <SERVER></SERVER> tages are only valid for Netscape. In IE you must use <script runat="server"></script> or the shorthand <% ...%>.

Similar Threads

  1. Apache freezing- help
    By mhoyt01 in forum Apache Development
    Replies: 8
    Last Post: July 22nd, 2003, 11:19 AM
  2. Add 2-3 pictures with just 1 article? (news- publishing system)
    By Stonescream in forum PHP Development
    Replies: 1
    Last Post: March 17th, 2003, 08:00 AM
  3. Targeting images to specific windows, does't work
    By pixeljunkie in forum HTML Programming
    Replies: 6
    Last Post: February 28th, 2002, 11:58 PM
  4. moving target algorithm needed.
    By Jonathon in forum Software Design
    Replies: 4
    Last Post: February 2nd, 2002, 12:42 AM
  5. Replies: 2
    Last Post: June 10th, 2000, 04:23 AM

IMN logo majestic logo threadwatch logo seochat tools logo