SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    England
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using Javascript to get part of the current URL

    Hi,

    We have an intranet which uses a number of servers. A form I have created uses server side processing that only works on a particular server. As the webpages/forms are the same on everypage I need to have a way of detecting the current server from the URL and then if this server is not the correct one, the user will be redirected to the correct server (probably using meta refresh).

    The incorrect server would be intranet. If someone accessed the form using http://INTRANET then they would need to be redirected to http://INT0802.

    My question is how do I detect if the URL is http://intranet/ ???

    Many thanks

    K

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    location.hostname will get you the server/host name.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript">
    
    var oRegExp = /^http:\/\/INTRANET/i;
    var url = self.location.href;
    if (oRegExp.test(url))
        self.location = url.replace(oRegExp, 'http://INT0802');
    
    </script>
    ::: certified wild guess :::


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
  •