Browser Identification JavaScript

  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

On my site I am currently having a problem with Netscape version 7.0 & 7.1. I have found a solution for the problem, but I want to apply this solution specifically to NS 7.0 & 7.1. So, I would like to identify those two browsers and then apply the fix only to users with those browsers. Does this proposal make since, and if so could someone offer a solution?

Thanks in advance,
PS: If someone knows how to do this with javascript that would be most helpful!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

I've tried to alert the appVersion just to see if I'm on the right track. But, that didn't even work.
Code: [ Select ]
   function Browser(){
    var brw = parseFloat(navigator.appVersion)
    if (brw >= 4.77){
        alert("AppVersion greater than 4.77")
    )
    else
    {
        alert("AppVersion less than 4.77")
    }
   }
  1.    function Browser(){
  2.     var brw = parseFloat(navigator.appVersion)
  3.     if (brw >= 4.77){
  4.         alert("AppVersion greater than 4.77")
  5.     )
  6.     else
  7.     {
  8.         alert("AppVersion less than 4.77")
  9.     }
  10.    }
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

I figured it out. I googled the question, and I got a lot of helpful snipits from various sites. I ended up doing it like this.

Code: [ Select ]
function Browser(){
    var Netscape;
    var spacerHeight = 0;
    Netscape = navigator.appName == "Netscape"
    if(Netscape){
        NetscapeVer = parseFloat(navigator.appVersion);
    }
  if((Netscape) && (NetscapeVer >= 5)){
        spacerHeight = 40
        return spacerHeight;
    }
    else
    {
        spacerHeight = 53
        return spacerHeight;
    }    
}
  1. function Browser(){
  2.     var Netscape;
  3.     var spacerHeight = 0;
  4.     Netscape = navigator.appName == "Netscape"
  5.     if(Netscape){
  6.         NetscapeVer = parseFloat(navigator.appVersion);
  7.     }
  8.   if((Netscape) && (NetscapeVer >= 5)){
  9.         spacerHeight = 40
  10.         return spacerHeight;
  11.     }
  12.     else
  13.     {
  14.         spacerHeight = 53
  15.         return spacerHeight;
  16.     }    
  17. }


This code allows me to determine whether the browser is netscape, and then sets the "spacerHeight" variable accordingly. First time doing browser identification. So, I was pretty happy that it worked for me. Hope this can help someone else.
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

I wrote this method a while back, not exactly sure how accurate it is, but it's never failed me...

http://www.kirupa.com/web/browser_detect.htm
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

I actually came up w/ what appears to be a much more complex version...of something similar. Your way...while I follow the code...I don't understand how you're differenciating the browser. I understand you extentiated each variable...but where did you come up w/ those values for the variables? That's just a question. Like I said I actually came up w/ a solution...here's what i did...

Code: [ Select ]
function Browser(){
    var Netscape;
    var spacer = "<td height=20>";
    var spacer1 = "<td height=40>";
    var spacer2 = "<td height=58>";
    var NetscapeVer;
    var Version;
    var platform;
    var navigatorOS = '';
    var Version2;
    if (typeof(window.navigator.platform) != 'undefined')
    {
        platform = window.navigator.platform.toLowerCase();
        if (platform.indexOf('win') != -1)
            navigatorOS = 'win';
        else if (platform.indexOf('mac') != -1)
            navigatorOS = 'mac'
        else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
            navigatorOS = 'nix';
    }
    Netscape = navigator.appName == "Netscape"
    if(Netscape){
        NetscapeVer = navigator.userAgent;
        Version = NetscapeVer.substring(80,83)
        Version2 = NetscapeVer.substring(87,90)
    }
    if ((navigatorOS == 'win') && (Version == 7.1))
    {
        document.write(spacer1)
    }
    if ((navigatorOS == 'mac') && (Version2 == 7.1))
    {
        document.write(spacer)
    }
    else
    {
    if (Version != 7.1)
        document.write(spacer2)
    }        
}
  1. function Browser(){
  2.     var Netscape;
  3.     var spacer = "<td height=20>";
  4.     var spacer1 = "<td height=40>";
  5.     var spacer2 = "<td height=58>";
  6.     var NetscapeVer;
  7.     var Version;
  8.     var platform;
  9.     var navigatorOS = '';
  10.     var Version2;
  11.     if (typeof(window.navigator.platform) != 'undefined')
  12.     {
  13.         platform = window.navigator.platform.toLowerCase();
  14.         if (platform.indexOf('win') != -1)
  15.             navigatorOS = 'win';
  16.         else if (platform.indexOf('mac') != -1)
  17.             navigatorOS = 'mac'
  18.         else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
  19.             navigatorOS = 'nix';
  20.     }
  21.     Netscape = navigator.appName == "Netscape"
  22.     if(Netscape){
  23.         NetscapeVer = navigator.userAgent;
  24.         Version = NetscapeVer.substring(80,83)
  25.         Version2 = NetscapeVer.substring(87,90)
  26.     }
  27.     if ((navigatorOS == 'win') && (Version == 7.1))
  28.     {
  29.         document.write(spacer1)
  30.     }
  31.     if ((navigatorOS == 'mac') && (Version2 == 7.1))
  32.     {
  33.         document.write(spacer)
  34.     }
  35.     else
  36.     {
  37.     if (Version != 7.1)
  38.         document.write(spacer2)
  39.     }        
  40. }
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

s15:

IE is the only browser that uses document.all

Old Netscape browsers used to use document.layers but they did away with that for getElemendByID

New Netscape doesn't support document.all, but does support getElementByID (IE has that too, which is why you have to check is document.all is not supported as well)

And well Opera uses window.opera, but you have to check for that first in the if statement otherwise it returns IE.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

Preciate it. Your way is much simpler. My way...I parsed through the navigator.userAgent to get the browser version. I combined this with navigator.platform to get the platform. It sounds easy when I write it out in english, but in code...your way is in deed much more direct and simplified. Thanks, next time I come accross a browser verificaiton issue...I'll deff. try your method. Thanks again for your input!
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Yeah the userAgent method is usually the most popular method of browser detection, and like I said, I don't know how accurate my method is, but I personally haven't had an issue with it so I will use it up until I experience one :)

Glad I could help :)

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 83 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.