SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Check for URL exists

    How to check whether an HTML file with a specified URL exist on the web server using javascript and if not redirect to an alternative URL

    Thanks in advance

    ipromote

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ipromote,

    You could try something like:

    if (document.URL != something) redirect2SomewhereElse();

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2001
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's not exactly I want.
    The above code will help me find out whether the URL's match but don't help me determine whether the file that is being represented by the URL actually exists.

    Any more ideas ?

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ipromote,

    Perhaps you'd best explain yourself more. Are you trying to determine if a user-entered URL is valid; that is, exists? The only way I know of is to actually go out there and see if you connect or get a 404 -- which means server-side.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  5. #5
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dont think youll be able to do it client side, but i have an idea to do it server side usng asp anda compents that comes with IIS (XMLHTTP) if you interested

    either post here or pm me

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2001
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually what I would like to achieve here is to fetch some content onto a page in all circumstances.

    Currently I have a perl script that fetches the content to all my pages through IFRAME or Javascript depending on whether the browser is IE or Netscape. But some times when cgi script server goes down the IFRAME tag still tries to fetch the URL and comes up with page not found error, instead I would like to call a javascript to get content from another source.

    For this I should know whether the Perl script is accessible at any point.

    Any clues ?

  7. #7
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cgi script server goes down the IFRAME tag still tries to fetch the URL and comes up with page not found error,
    sounds like a catch22 to me. If your server is down how will it know that that page was unavailable? Any rate, this is a server-side question.

    The only thing you can do for the iframe is assign a function to the src -- <iframe src='javascriptage2Display()'....> -- the function should return a valid page to load.

    At present, I'm presuming your cgi is processing the page somehow; well, when it gets the 'page not found' error (the perl people should know how) you substitute the other page and return it.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •