1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript Needed - test if a web page is there or not

Discussion in 'JavaScript' started by SDTEAM, Feb 15, 2006.

  1. #1
    Hello, I am looking for a piece of Javascript that will check to see if a web page is available at a particular domain - and if the page is available then to redirect to it, however if the page is not available then redirect to an alternative page at a different domain.

    ...this seems like it should be fairly simple - so if anyone can help I would apreciate it.

    thanks for looking at my post :)
     
    SDTEAM, Feb 15, 2006 IP
  2. Jowan Pasco

    Jowan Pasco Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You would probably need some backend support for that. It's basically AJAX. Say, you write a page that takes a url as a parameter, and if that url is valid, outputs something like this:

    <script type="text/javascript">
    window.parent.redirectTo("http://valid.url.here.com");
    </script>

    Then in your main page, you define this:

    function redirectTo(id) {
    location.href = id;
    }

    Then use a hidden iframe to load your backend url, and voila.
     
    Jowan Pasco, Mar 2, 2006 IP
  3. SDTEAM

    SDTEAM Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for your response, and you are right the function to redirect to a url works well, however how do I test to see if I should redirect to the url? (if the webserver is offline the user wont see anything)

    can this be done with javascript?

    for example if the webpage "http://www.asiatic-lion.org/gallery/chester1.html" can be found by the browser then redirect to it, otherwise redirect to "http://bbc.co.uk"
     
    SDTEAM, Mar 9, 2006 IP
  4. Jowan Pasco

    Jowan Pasco Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you want to do this entirely client-side, without backend support, then XMLHttpRequest object might work for you. Check out this tutorial - http:/developer.apple.com/internet/webcontent/xmlhttpreq.html , or google "xmlhttprequest". You'd need a small subset of its functionality - basically just to check if a page is there or not. There is a 'status' attribute, it might work for you.
     
    Jowan Pasco, Mar 9, 2006 IP
    SDTEAM likes this.
  5. marty

    marty Peon

    Messages:
    154
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    marty, Mar 9, 2006 IP
    SDTEAM likes this.
  6. SDTEAM

    SDTEAM Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you both for your help, I may not get a chance to sort this out immediately but the links to "http://www-128.ibm.com/developerworks/java/library/wa-ajaxintro3/index.html" and "http:/developer.apple.com/internet/webcontent/xmlhttpreq.html" look very useful.

    I must admit I had not heard of the "XMLHttpRequest" object, hopefully I can sort out everything over the next few days.... (after the weekend).

    once again thank you, the help is very much apreciated.
     
    SDTEAM, Mar 10, 2006 IP