SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    is this possible in javascript: check if url exists?

    Hi,

    I have a problem with checking if a file exists. Due to server restrictions, I cant do this in PHP so I am hoping there is a way to do it in javascript.

    I have a page that passes $day, $date and $year through a form.

    These are then used in a url like this track$day$month$year.html ie: track12022003.html

    What I need is the code to check if the file exists, if it does it will go that file and if it doesnt it will go to noresults.html

    ie:
    PHP Code:
    file track$day$month$year.html
    if(file exists){
     
    go to the file's url
    else{
     the file doesnt exist so load the noresults.html fil;e

    Any help with this is appreciated.

    Thanks,
    Martin

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Why not generate the file's name in PHP and check the filesystem server-side before you send any content to the browser? Seems like a better solution to your problem than doing a bunch of computations client-side.

  3. #3
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript does not have that ability since it is a client side language. Why do they allow the use of PHP, but not check if a file exist? Seems strange.

  4. #4
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    thanks for the reply.

    The filename is already generated on PHP but all the PHP work is done on one of our internal servers which then FTP's all the HTML to a production web server. This server does not have PHP installed and the I.T. guys downstairs wont install PHP so I have to work around their restrictions - thats why i was hoping there was a way to do it in javascript

    I had a nice clean PHP file to do this but now that it is on the non PHP server I need a workaround.

    Thanks,
    Martij

  5. #5
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    I used a search for image function.

    I don't know if it helps, but you could assign a small pic to each document, and check if the picture exists by using the onError. If it exists, then bring in the relevent info.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


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
  •