Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    cuz
    cuz is offline
    New Coder
    Join Date
    Mar 2003
    Location
    New Chursey
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    detecting the OS AND forwarding to another page

    Hello, All. I have to create a JS that not only detects a computer's OS, (in this case, just Mac) but also forwards the user to another page based on the results of the detection. I've found tons of ways to detect the OS, but none that can forward the user to a certain page afterwords. Can anyone help me out?

    Thanx in advance...
    -cUz

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <script language="JavaScript1.2" type="text/javascript">
    if (navigator.userAgent.indexOf("Win")) {
      location.replace("windows.html");
    } else if (navigator.userAgent.indexOf("Mac")) {
      location.replace("macintosh.html");
    } else {
      location.replace("other.html");
    }
    </script>

  • #3
    cuz
    cuz is offline
    New Coder
    Join Date
    Mar 2003
    Location
    New Chursey
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It worked like a charm goose!!!! THANX!!!!!
    -cUz

  • #4
    cuz
    cuz is offline
    New Coder
    Join Date
    Mar 2003
    Location
    New Chursey
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, I spoke too soon...

    The code is working for Windows bit not for Maca,

    Here's my code:

    <script language="JavaScript1.2" type="text/javascript">
    if (navigator.userAgent.indexOf("Win")) {
    location.replace("http://www.eh21.com/shop/");
    } else if (navigator.userAgent.indexOf("Mac")) {
    location.replace("http://www.eh21.com/shophtml/");
    } else {
    location.replace("http://www.eh21.com/shophtml/");
    }
    </script>
    -cUz

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry I don't have a mac I can test it on. Try doing alert(navigator.userAgent); then see the output. The indexOf function is case sensitive, maybe thats the problem.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by x_goose_x
    The indexOf function is case sensitive, maybe thats the problem.
    Yes it is; you need to check it in lower case:

    var agt = navigator.userAgent.toLowerCase();

    if(agt.indexOf("mac")!=-1) {
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #7
    cuz
    cuz is offline
    New Coder
    Join Date
    Mar 2003
    Location
    New Chursey
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey guys. First and foremost, thanx for all your help!!!!!!!

    I pasted the following code in my page. Unfortunatly I still can't get it to work for Macs:

    Code:
    <script language="JavaScript1.2" type="text/javascript">
    var agt = navigator.userAgent.toLowerCase();
    if(agt.indexOf("mac")!=-1) {
      location.replace("macintosh.html");
    } else if(agt.indexOf("win")!=-1) {
      location.replace("windows.html");
    } else {
      location.replace("other.html");
    }
    </script>
    Am I doing something way off base here?

    Thanx in advance...
    -cUz

  • #8
    cuz
    cuz is offline
    New Coder
    Join Date
    Mar 2003
    Location
    New Chursey
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    COMPLETLY ignore that last post! It works perfectly...I just did something wrong on my end.

    Thanx to goose & brother for their help!
    -cUz


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •