SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP!!!! Redirect script - check exists first

    CALLING CLEVER PEOPLE ON THIS FORUM!!! I NEED YOUR HELP!
    OK, here's the poop: i need a javascript that checks if the file exists first, if it doesn't i want it to show no.html

    Why? the files i want it to show are on a server, if the server is turned off i need to tell people this (info in no.html)

    example - try to connect to http://martin/atj/index.html
    if it can't find it then display local file no.html

    CATCH - the pages are on the intranet NOT the internet
    (don't know if this makes a difference or not)

    Thank you for reading, let me know if it can be done
    it's probably really simple but i'm new to all this and it's baffling without a decent college course!

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    UK
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JavaScript is a client side scripting language, not server side. Thus there is no way to know if a file exists using JavaScript.

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thank you

    Thank you very much for replying, it's interesting to learn as i'm going along.
    i obviously haven't had a lot of training on this!

    Is there any other way to do it, maybe using vbscript or java?
    Thanks anyway.

  4. #4
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Redirect if a page is not available

    Try this...

    Create a file on the server, mine is called imhere.htm
    in it put

    <script language=javascript>
    parent.location.href="index.html";
    </script>

    Create a file on the client, in it put

    <html><head></head><body>
    <iframe style="display:none" src="http://myserver/imhere.htm"></iframe>
    <br><br><center>File not found</center>
    </body></html>

    OR, if you want a different page to display if the one is not available then this would be in the file on the client

    <frameset border=0 rows="0,*">
    <frame src="http://myserver/imhere.htm">
    <frame src="http://www.google.com">
    </frameset>

    I then make the file on the client the homepage for the browser. If I am connected to my intranet (so that imhere.htm is read) then I am redirected to index.html, if not I get google.

  5. #5
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make XMLHTTPRequest to remote site and check status property. If it's not 200, redirect to notfound page:

    Code:
    var url = "http://martin/atj/index.html";
    var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    xmlhttp.open("GET", url, false);
    xmlhttp.send();
    if(xmlhttp.status == 200)
        document.location.href = url;
    else
        document.location.href = "no.html";


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
  •