Solved

Detect N2/N3/N4/IE2/IE3/IE4 + subversion + Jscript

Posted on 1998-05-08
21
198 Views
Last Modified: 2008-02-01
I need a generic Javascript that give all the OS and Browser info that is available,
nicely cut into small parts.

I don't know exactly how to frase my question more explicitly, but this is a try
(don't hurt me if if respond with: cut that into nice parts too):
I don't know which information is accessible without a CGI script, must give as much of the
following as possible:

 a - Will not give errors with any regular browser (N2/3/4, MSIE2/3/4, Opera: any platform)
 b - Set VAR Browser to "Netscape" or "MSIE" (or to others, "Opera" or whatever exotic
stuff is available)
 c - Set VAR Version to "2" or "3" or "4" or whatever version when appropriate
 d - Set VAR Subversion to ".03" or "0.1.revB" or ".2" or whatever subversion/revision when appropriate
 e - Set VAR JVS to "1.0" or "1.1" or whatever Javascript version when appropriate
 f -  Set OS to the most specific name and SubVersion (OS="WIN" SV="NT" SVadd="5")
g -  To test, display a message, or generate a new HTML page or frame showing everything.

This is tough due to the amount of work involded.
I start with 400 points.

Merci,
 Jan
0
Comment
Question by:luiaard
  • 8
  • 5
  • 3
  • +3
21 Comments
 
LVL 10

Expert Comment

by:kollegov
ID: 1277589
That's nearly all info one can get about browsers
and OS. Unfortunatly JavaScript do not have a good way to obtain operating System, but Java have. On case Java isn't ON or non-java browser you can try to parse major OSes from appVersion
as I do in script below for win95, winNT and Mac.

The most sad that only one num after point in most browsers
is available so you can't get NN3.02 you will get only 3.0


<html>
<head>
<script>
var JSV="1.0"
</script>
<SCRIPT language="JavaScript1.1">
JSV="1.1"
</script>
<SCRIPT language="JavaScript1.2">
var JSV="1.2"
</script>
<script>
var browser="unknown";
var version="unknown";
var subversion="unknown";
var OS="unknown";
if(navigator.appName)    browser=navigator.appName;
if(navigator.appVersion)
   {aver=navigator.appVersion
    version=aver.charAt(0);
    inx=aver.indexOf(".");
    if(inx!=-1)
      subversion=aver.substring(inx+1);
   }

//first, we will try to obtain OS from Java, if possible

if(java)
  {if(navigator.javaEnabled()==true)
    {OS=java.lang.System.getProperty("os.name");}
  }

// on case we can't get it through Java
if(OS=="unknown")
  {if(navigator.appVersion)
    {if(aver.indexOf("Win")!=0)
       {OS="Win";
        if(aver.indexOf("95")!=0) OS+="95";
        if(aver.indexOf("NT")!=0) OS+="NT";
       }
     if(aver.indexOf("Mac")!=0)   OS="Mac";
     // and so on ... unfortunatly this is not best
     // way to solve problem        
     // You can try to parse more OSes/browsers if you know
     // it's signatures
    }
  }

</script>

</head>
<body>

<center><!--#geoguide--></center>
<script>
 if(navigator.appVersion) document.writeln("appVersion: "+navigator.appVersion+"<br>")
 if(navigator.appName)    document.writeln("appName: "+navigator.appName+"<br>")
 if(navigator.appCodeName)document.writeln("appCodeName: "+navigator.appCodeName+"<br>")
 if(navigator.userAgent)  document.writeln("userAgent: "+navigator.userAgent+"<br>")
 if(navigator.platform )  document.writeln("platform: "+navigator.platform+"<br>")
 if(navigator.language )  document.writeln("language: "+navigator.language+"<br>")
 if(JSV)  document.writeln("JavaScript:"+JSV+"<br><br>")
</script>
<br>
<b>Data obtained through  Java package:
Accessable only with Java enabled browsers:</b>
<br>
<script>
 if(java)
   if(navigator.javaEnabled()==true)
     {document.writeln('javaVersion: '+java.lang.System.getProperty("java.version")+"<br>");
      document.writeln('javaVendor: '+java.lang.System.getProperty("java.vendor")+"<br>");
      document.writeln('java.class.version : '+java.lang.System.getProperty("java.class.version")+"<br>");
      document.writeln('Operating system name: '+java.lang.System.getProperty("os.name")+"<br>");
      document.writeln('Operating system architecture : '+java.lang.System.getProperty("os.arch")+"<br>");
     }
</script>
<br><br>

<b>As much as possible from your request:
</b><br>


<script>
 document.writeln("version="+version+"<br>");
 document.writeln("subversion="+subversion+"<br>");
 document.writeln("JavaScript="+JSV+"<br>");
 document.writeln("OS="+OS+"<br>");
</script>

</body>
</html>
0
 

Author Comment

by:luiaard
ID: 1277590
With Java disabled, N4 gave 2 errors: Kollegov,
which is in conflict with condition a (Will not give errors with any regular browser)

java is not defined and unterminated string literal.
         document.writeln('java.class.version :
..........................^

They must be avoided.
Otherwise, the script is excellent.
Please modify.

0
 
LVL 10

Expert Comment

by:kollegov
ID: 1277591
Well, I corrected this problem, sorry, missed it.
Just forgot that MIE do not allow to call java package methods
only applet methods can be called.
So if you still interested to obtain some
additional info about browser though java I can create
special applet for this. MIE allows to call applet methods,
so this is only technical problem. :)

But if you want to limit yourself with javaScript solution
there is complete info you can obtain, nothing more :(

Generally you can get only browser, version (including OS sometimes) and try to parse OS out of this info if it's included.
There is no difficalties with JSV as you can see.

Main difficalties are with OS. there are too many OSes to
detect all and there are too many differences between all existing browsers to do this correctly.
The only direct way to get OS name through java, but not all browsers are supporting Java and interaction between Java and JavaScript. as I know (MIE4+ and NN3+ only)

I do not want to waste my time for this 'special' applet if
you do not want this way, but if you need I can do it..


In edition below, only Netscape will give additional info
I disabled this for other non-live-connect browsers

</script>
<SCRIPT language="JavaScript1.1">
JSV="1.1"
</script>
<SCRIPT language="JavaScript1.2">
var JSV="1.2"
</script>
<script>
var browser="unknown";
var version="unknown";
var subversion="unknown";
var OS="unknown";
if(navigator.appName)    browser=navigator.appName;
if(navigator.appVersion)
   {aver=navigator.appVersion
    version=aver.charAt(0);
    inx=aver.indexOf(".");
    if(inx!=-1)
      subversion=aver.substring(inx+1);
   }

var brOK=false;
if(navigator.appName.indexOf("Netscape")!=-1)
{brOK=navigator.javaEnabled();}

if(brOK)
  {if(navigator.javaEnabled()==true)
    {OS=java.lang.System.getProperty("os.name");}
  }

if(OS=="unknown")
  {if(navigator.appVersion)
    {if(aver.indexOf("Win")!=0)
       {OS="Win";%
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1277592
Well, I corrected this problem, sorry, missed it.
Just forgot that MIE do not allow to call java package methods
only applet methods can be called.
So if you still interested to obtain some
additional info about browser though java I can create
special applet for this. MIE allows to call applet methods,
so this is only technical problem. :)

But if you want to limit yourself with javaScript solution
there is complete info you can obtain, nothing more :(

Generally you can get only browser, version (including OS sometimes) and try to parse OS out of this info if it's included.
There is no difficalties with JSV as you can see.

Main difficalties are with OS. there are too many OSes to
detect all and there are too many differences between all existing browsers to do this correctly.
The only direct way to get OS name through java, but not all browsers are supporting Java and interaction between Java and JavaScript. as I know (MIE4+ and NN3+ only)

I do not want to waste my time for this 'special' applet if
you do not want this way, but if you need I can do it..


In edition below, only Netscape will give additional info
I disabled this for other non-live-connect browsers

</script>
<SCRIPT language="JavaScript1.1">
JSV="1.1"
</script>
<SCRIPT language="JavaScript1.2">
var JSV="1.2"
</script>
<script>
var browser="unknown";
var version="unknown";
var subversion="unknown";
var OS="unknown";
if(navigator.appName)    browser=navigator.appName;
if(navigator.appVersion)
   {aver=navigator.appVersion
    version=aver.charAt(0);
    inx=aver.indexOf(".");
    if(inx!=-1)
      subversion=aver.substring(inx+1);
   }

var brOK=false;
if(navigator.appName.indexOf("Netscape")!=-1)
{brOK=navigator.javaEnabled();}

if(brOK)
  {if(navigator.javaEnabled()==true)
    {OS=java.lang.System.getProperty("os.name");}
  }

if(OS=="unknown")
  {if(navigator.appVersion)
    {if(aver.indexOf("Win")!=0)
       {OS="Win";
        if(aver.indexOf("95")!=-1) OS+="95";
        if(aver.indexOf("NT")!=-1) OS+="NT";
       }
     if(aver.indexOf("Mac")!-1)   OS="Mac";
     // and so on ... unfortunatly this is not best
     // way to solve problem        
    }
  }

</script>

</head>
<body>

<center><!--#geoguide--></center>
<script>
 if(navigator.appVersion) document.writeln("appVersion: "+navigator.appVersion+"<br>")
 if(navigator.appName)    document.writeln("appName: "+navigator.appName+"<br>")
 if(navigator.appCodeName)document.writeln("appCodeName: "+navigator.appCodeName+"<br>")
 if(navigator.userAgent)  document.writeln("userAgent: "+navigator.userAgent+"<br>")
 if(navigator.platform )  document.writeln("platform: "+navigator.platform+"<br>")
 if(navigator.language )  document.writeln("language: "+navigator.language+"<br>")
 if(JSV)  document.writeln("JavaScript:"+JSV+"<br><br>")
</script>
<br>
<b>Data obtained through  Java package:
Accessable only with Java  and LiveConnect enabled browsers (Netscape):</b>
<br>
<script>
   if(brOK==true)
     {document.writeln('javaVersion: '+java.lang.System.getProperty("java.version")+"<br>");
      document.writeln('javaVendor: '+java.lang.System.getProperty("java.vendor")+"<br>");
      document.writeln('java.class.version : '+java.lang.System.getProperty("java.class.version")+"<br>");
      document.writeln('Operating system name: '+java.lang.System.getProperty("os.name")+"<br>");
      document.writeln('Operating system architecture : '+java.lang.System.getProperty("os.arch")+"<br>");
     }
</script>
<br><br>

<b>As much as possible from your request:
</b><br>


<script>
 document.writeln("version="+version+"<br>");
 document.writeln("subversion="+subversion+"<br>");
 document.writeln("JavaScript="+JSV+"<br>");
 document.writeln("OS="+OS+"<br>");
</script>

</body>
</html>
0
 

Expert Comment

by:CyberMage
ID: 1277593
I am not sure if it will work with Opera, but maybe someone e else will know how to add the rest of the stuff that you want in it...here's my try at it:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<TITLE>My Home On The Web, Browser Information: Version 9</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
// This script was written by Michael Lauzon, (C) 1998
// And not to be used without the express and written
// consent of its author: ce940@freenet.toronto.on.ca
// Visit my homepage at:
// http://www.geocities.com/SiliconValley/Way/9180/
var browserStr = '<BO' + 'DY BGCOLOR="WHITE" TEXT="BLACK">';
var ie = (navigator.appVersion.indexOf('MSIE') != -1);
function browserInfo() {
  browserStr += "Browser: " + navigator.appName + "<BR>\n";
  browserStr += "Version: " + navigator.appVersion + "<BR>\n";
  browserStr += "Codename: " + navigator.appCodeName + "<BR>\n";      browserStr += "User agent: " + navigator.userAgent + "<BR>\n";
  browserStr += "Platform: " + ((navigator.platform)?(navigator.platform):("Not available")) +
 "<BR>\n";
  browserStr += "Language: " + ((navigator.language)?(navigator.language):("Not available")) + "<BR>\n";
  if (!ie) {
    if (navigator.javaEnabled) browserStr += "Java enabled: " + ((navigator.javaEnabled())?("Yes"):("No")) + "<BR>\n";
      else browserStr += "Java enabled: information not available<BR>\n";
        browserStr += "JavaScript enabled: Yes<BR>\n";
  }
  if (navigator.mimeTypes) {
    if (navigator.mimeTypes.length == 0) browserStr += "Mime types not available<BR>\n";
      else {
        browserStr += '<P><TA' + 'BLE BORDER WIDTH="100%"><TR><TD>Suffixes</TD><TD>Enabled plugin</TD><TD>Description</TD><TD>Mimetype</TD></TR>';            
        for (var i=0,n=navigator.mimeTypes.length;i<n;i++) {
          browserStr += "<TR><TD>" + navigator.mimeTypes[i].suffixes      + "</TD>";
          if (navigator.mimeTypes[i].enabledPlugin)
            browserStr += "    <TD>" + navigator.mimeTypes[i].enabledPlugin.name + "</TD>";
            else browserStr += "    <TD> </TD>"
              if (navigator.mimeTypes[i].description)
                browserStr += "    <TD>" + navigator.mimeTypes[i].description   + "</TD>";
                else browserStr += "    <TD> </TD>"
                  browserStr += "    <TD>" + navigator.mimeTypes[i].type + "</TD></TR>\n";
        }
        browserStr += '</TA' + 'BLE>';
     }
  }

  if (navigator.plugins) {
    if (navigator.plugins.length == 0) browserStr += "Plugin information not available<BR>\n";
      else {
        browserStr += '<HR><P><TA' + 'BLE BORDER WIDTH="100%"><TR><TD>Plugin Name</TD><TD>Filename</TD><TD>Description</TD></TR>'            
        for (var i=0,n=navigator.plugins.length;i<n;i++) {
          browserStr += "<TR><TD>" + navigator.plugins[i].name + "</TD>";
          browserStr += "    <TD>" + navigator.plugins[i].filename    + "</TD>";
          browserStr += "    <TD>" + navigator.plugins[i].description + "</TD></TR>\n";    
        }
        browserStr += '</TA' + 'BLE></BO' + 'DY>';
     }
  }

}

function showBrowserInfo() {
  parent.browserInfo();
  parent.frames[1].document.open();
  parent.frames[1].document.write(parent.browserStr);
  parent.frames[1].document.close();
}

var Button = '<HT' + 'ML>\n';
Button += '<BO' + 'DY BGCOLOR="WHITE" TEXT="BLACK">';
Button += '<FO' + 'RM><INP' + 'UT TYPE="BUTTON" VALUE="Show Browser Info" onClick="parent.showBrowserInfo();"></FO' + 'RM>\n';
Button += '</BO' + 'DY>';
Button += '</HT' + 'ML>\n';
   
var Empty = '<HT' + 'ML><BO' + 'DY BGCOLOR="WHITE" TEXT="BLACK"></HT' + 'ML>\n';
// -->

</SCRIPT>
</HEAD>
<FRAMESET ROWS="50,*">
<FRAME NAME="Button" SRC="javascript:parent.Button" SCROLLING="NO" NORESIZE>
<FRAME NAME="Empty" SRC="javascript:parent.Empty" SCROLLING="YES" NORESIZE>
</FRAMESET>
</HTML>

0
 

Author Comment

by:luiaard
ID: 1277594
Hey, I just cut and past it from my page...and I am giving you permission to use it
If you don't believe me, then email me at the email address in my code; and I will email you back.
The only thing that I ask is, if you decide to use my code...and anyone (or yourself) makes a fix to it:
then email me with the new source code.
0
 

Expert Comment

by:CyberMage
ID: 1277595
Luiaard, you don't answered my question about way to obtain
OS name through Java applet. Do you need it?

Hi, CyberMage, do you think you give better approach than
my last comment? Your 'answer' do not give more info
than particular

appName
appVersion
appCodeName

It do not detect JavaScript version

do not split the Version number to Major version, subversion
and OS,  it just gives some more info about  plugins
and mime types, which wasn't requested.

0
 
LVL 10

Expert Comment

by:kollegov
ID: 1277596
Kollegov: I do not care about the means, I just care about the result.
If the call to Java makes the result better, then I need it.
If it causes any errors in some cases, and in other cases gives a better
result, then I do not need it.

Cybermage: Thank you for committing your result. I'm a bit food-poisened
right now, so it will take me some days to evaluate your answer (or get to
out of bed :-((    .

With regards,
 Luiaard
To everyone: I will evaluate the results as soon as I can.
Please hold on, and get on submitted.


0
 

Author Comment

by:luiaard
ID: 1277597
Well, I can't post here Java Applet :)
So the URL is
http://www.geocities.com/siliconvalley/lakes/8620/browserinfo.html

0
 
LVL 10

Expert Comment

by:kollegov
ID: 1277598
Kollegov, upon receiving a email from you
containing the Java class + source, stating it is free of copyrights (send it to my work-email: MOSI@euronet.nl  so that I can receive it ASAP ),
I will accept your answer (submit here how I must install the applet)
with a A-grade.

Cybermage's: thanks for your efforts. Kollegov's answer is nicer.

Thanks,
 luiaard
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:luiaard
ID: 1277599
Michael:  You really should take out that copyright message - I wrote half that script and half of what I worte came from another script originally from Eric Krock of Netscape and he got help from JF (whoever that is)...
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1277600
There is a well-tested script to detect browser vendor, browser version, and OS at the following location:

http://developer.netscape.com:80/docs/examples/javascript/browser_type.html

Brian
0
 

Expert Comment

by:btphelps
ID: 1277601
Hm... looks like you accepted not my answer, but one
from btphelps..
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1277602
Sorry, looks like EE totally messed, previously it shows
btphelps answer as accepted, now it shows my comment
as btphelps' proposed answer. Meanwhile in
main javascript section question is shown as 'locked'...
This all looks like totally messed :)


Well, I'm going to e-mail you datacollector.class, .java source
and HTML  example, I also e-mailed
this HTML source with additional comments about applet usage/installation, I avoid wrapping problems, so I do not
post it here.



0
 
LVL 10

Expert Comment

by:kollegov
ID: 1277603
mplungjan,

CyberMage's script also includes the IE bug fix (workaround really) from me.  Exactly which part of the script did CyberMage actually write?

Trevor.


0
 
LVL 5

Expert Comment

by:Trevor013097
ID: 1277604
I do not think that discussion belongs here. Can I send a mail to
postmaster@smallcomputersailing.com in the isles? ;-)

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1277605
mplungjan.

By all means do.  tmunday@pcmaritime.co.uk should get you through.

Trevor.
0
 
LVL 5

Expert Comment

by:Trevor013097
ID: 1277606
Well, I am a bit confused who's wrote what and whoms answer to accept right now.
Virtueel send me a email with the answer. Who shall that be?

I'm inclined to asked Kollegov's answer.

0
 

Author Comment

by:luiaard
ID: 1277607
luiaard,

I would go for kollegov's answer aswell, in my opinion it is more robust and returns more information.

Trevor.

0
 
LVL 5

Expert Comment

by:Trevor013097
ID: 1277608
Luiaard, in such cases I usually suggest to share points
(from my own ones, which I do not know how to use) with
other expert, but I do this when I see that other answer
have something really valuable. In this case CyberMage
do not add anything new even to my first rejected answer.
But if you beleive that CyberMage also need to be granted with points for his work, tell me what value I should post as a 'special' question for him in order to share.

0
 
LVL 10

Accepted Solution

by:
kollegov earned 400 total points
ID: 1277609
Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now