Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Version sniffing

Status
Not open for further replies.

ronsig

Programmer
May 24, 2001
54
IL
Hi

I'm trying to sniff out the exact browser version used, but all IE versions return "4". How can I distinguish between 5, 5.5, 6 etc.?

Thanks,
Ron
 
I don't know if I am reading your post correctly, but to find out the version of the browser being used you would open IE and click on Help then select about Internet Explorer. Or you can also right click on My Computer and select properties and it will tell you under the General Tab.
 
I assume you mean via a program? What language are you using, is it via a webpage or stand-alone program?
 
I'm using javascript

And I've found out how to retrieve it (using navigator.userAgent)
 
Try using some of this code and see how you do:


function browserVer()
{
// :Variables:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
flag = 0; //Flag used to determine if browser was found.
string = ""; //Browser will hold the name of the current browser.
test = navigator.userAgent.split(" "); //Test is used to hold userAgent after being "split" into an array.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//alert(navigator.userAgent);
for(x = 0; x < test.length; x++)
{
switch (test[x])
{
case &quot;Opera/5.12&quot;://Catch Opera 5.12 identified as Opera
string = &quot;1: Opera 5.12&quot;;
browser = &quot;1&quot;;
flag = 1;
break;

case &quot;Opera/6.0&quot;://Catch Opera 6.0 identified as Opera
string = &quot;2: Opera 6.0&quot;;
browser = &quot;2&quot;;
flag = 1;
break;

case &quot;Opera&quot;://Catch Opera not identified as Opera
string = &quot;3: Opera &quot; + test[x+1];
browser = &quot;3&quot;;
flag = 1;
break;

case &quot;MSIE&quot;://Catch IE (tested on 6.0 successfully)
string = &quot;4: IE ver &quot; + test[x+1];
browser = &quot;4&quot;;
break;

case &quot;Netscape6/6.2&quot;://Catch Netscape 6.2
string = &quot;5: Netscape 6.2&quot;;
browser = &quot;5&quot;;
flag = 1;
break;

case &quot;Netscape6/6.2.1&quot;://Catch Netscape 6.2.1
string = &quot;6: Netscape 6.2.1&quot;;
browser = &quot;6&quot;;
flag = 1;
break;

default:
//Catch Netscape (tested on 4.7 successfully)
if (flag != 1)
{
if (navigator.appName == &quot;Netscape&quot;)
{
string = &quot;Default: Netscape &quot; + parseFloat(navigator.appVersion);
browser = &quot;default&quot;;
}
}
break;
}
if (flag == &quot;1&quot;)
{
break; //Exit loop
}
}
//alert(browser);
alert(string);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top