SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a sniffer that sends Netscape and IE users to different locations.
    However, I want to send Netscape 6 users to the same location as IE users.
    Any advice.
    Here's my current sniffer code:


    var ua = 0;
    var bd = 0;
    var av = 0;

    // can we get browser & os info?
    if(navigator.userAgent)
    ua = navigator.userAgent.toLowerCase();
    if(navigator.appName)
    bd = navigator.appName.toLowerCase();

    // if yes,
    if(ua){
    // if M$ os,
    if((ua.indexOf("win")!=-1)||(ua.indexOf("windows")!=-1)){
    if(bd.indexOf("netscape")!=-1)
    window.location.href="index_NN.cfm";
    else if(bd.indexOf("microsoft")!=-1)
    window.location.href="index-new.cfm";

    // if mac os,
    } else if((ua.indexOf("mac")!=-1)||(ua.indexOf("ppc")!=-1)){
    if(bd.indexOf("netscape")!=-1)
    window.location.href="index_NN.cfm";
    else if(bd.indexOf("microsoft")!=-1)
    window.location.href="index-new.cfm";

    }

    // if no,
    } else {
    window.location.href="index_NN.cfm";
    }

  2. #2
    SitePoint Enthusiast Rips's Avatar
    Join Date
    Mar 2001
    Location
    London, UK
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Arite man,

    You write your sniffer to look for document.getElementById. This is a DOM method that Netscape 6 supports, but not Netscape Navigator 4.x.

    E.g

    // Detect Netscape 6 and redirect to same page as IE users
    else if (document.getElementById) {
    window.location.href="index-ie.htm";
    }

    Check out Netscape 6: Detection and Scripting on webreference.com
    Last edited by Rips; Apr 12, 2001 at 09:10.

  3. #3
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's what I use:

    <script language="JavaScript">
    <!--
    var agt=navigator.userAgent.toLowerCase();
    var is_win = (agt.indexOf("win")!=-1);
    var is_mac = (agt.indexOf("mac")!=-1);

    var IE4 = (document.all && !document.getElementById) ? true : false;
    var NS4 = (document.layers) ? true : false;
    var IE5 = (document.all && document.getElementById) ? true : false;
    var NS6 = (document.getElementById && !document.all) ? true : false;

    // -->
    </script>

    You can then use an 'if' like so:

    if (IE4 || IE5 || NS6)
    {window.location.href = 'ieAndNS6.html' }
    else
    {window.location.href = 'netscape4.html' }

  4. #4
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    scrubz...so that is the script in its entirety? That little chunk of code is your entire sniffer? If it's not, would you mind posting the whole lot?

    I love it when people write good clean small code.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  5. #5
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's the whole sha-bang.

    It doesn't deal with older browsers, Opera, or anything else -just IE & NS 4 and above.

    To check for any of the conditions (is_mac, is_win, IE4, etc.), you only need to say:

    if (is_win)
    { ...do something... }

    if (is_win) is a shortcut way of saying if (is_win == 'true')

  6. #6
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok...is there a line that you can add that will say "if you are not one of these browsers then go here"?

    something like

    if (!is_win && !is_mac)
    {window.location.href = 'upgrade_your_browser_you_idiot.html' }


    Would something like that work? I really only care about supporting newer browsers, but I don't want people with older browser to get totally shut out.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  7. #7
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, use 'else ifs' to perform the action you want, depending on the browser, and end the whole statement with an 'else' to cover any other broswer not mentioned:


    if (IE4)
    {alert('IE 4');}
    else if (IE5)
    {alert('IE 5');}
    else if (NS6)
    {alert('Netscape 6');}
    else
    {alert('None of the above');}

  8. #8
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And by the way, your statement above would work, but it's checking for Macintosh vs. something running Windows OS, instead of checking the browser (so we can detect those folks using a Commodore 64).

  9. #9
    SitePoint Addict
    Join Date
    Jul 2001
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just thought I would post to say THANKS!

    You guys are excellent. This redirect is exactly what I have been looking for for the past 2 hours on a variety of sites and in different forums here.

    Cheers!


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
  •