SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member anson's Avatar
    Join Date
    Oct 2003
    Location
    sf
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    js sniffer/redirect/stylesheet-disher outer help

    Hey guys,
    I'm about to upload a site that uses the following script to dish out stylesheets and redirect old browsers. I hacked a couple different scripts together, and think it works, but i dont have an old version of ie to test on.

    Can anyone look this over for me and tell me how i can improve it?
    Theres probably some dumb errors, as I am new to js.

    Thanks in advance,

    Anson

    code follows:
    ----------------


    <script type="text/javascript"><!--
    var IE4 = (navigator.appVersion.indexOf("MSIE") > 0);
    var Netscape = (navigator.appName == "Netscape");
    if(Netscape) {
    var NetscapeVer = parseFloat(navigator.appVersion);
    }
    var OPERA = navigator.userAgent.indexOf("Opera") > -1;
    var SAFARI = navigator.userAgent.indexOf("Safari") > -1;
    var OS;
    if (navigator.appVersion.indexOf("Win") > 0) OS = "Windows";
    if (navigator.appVersion.indexOf("Mac") > 0) {OS = "MacOS";}

    switch (OS) {
    case "Windows":
    if (IE4 > 0) window.location="error.html";
    if (NetscapeVer < 5) window.location="error.html";
    if (NetscapeVer >= 5) window.location="error.html";
    if (OPERA > 0) window.location="error.html";
    break;
    case "MacOS":
    if (SAFARI > 0) window.location="error.html";
    if (IE4 > 0) document.write ('<link href="../macIE.css" rel="stylesheet" type="text/css">');
    if (NetscapeVer < 5) window.location="error.html";
    if (NetscapeVer >= 5) window.location="error.html";
    if (OPERA > 0) window.location="error.html";

    break;
    }
    //-->
    </script>

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I now only use minimal browser-detection - unfortunately it's still needed in some areas. Here's the sniffing I'm currently using:
    Code:
    if(window.opera){
      xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
      if (!xOp7) {
        xOp5or6=(xUA.indexOf('opera 5')!=-1 ||
                 xUA.indexOf('opera/5')!=-1 ||
                 xUA.indexOf('opera 6')!=-1 ||
                 xUA.indexOf('opera/6')!=-1);
      }
    }
    else if(document.layers) {xNN4=true;}
    else {
      xIE4Up=document.all &&
             xUA.indexOf('msie')!=-1 &&
             parseInt(navigator.appVersion)>=4;
    }
    Check for window.opera first, because it can spoof


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
  •