PDA

Click to See Complete Forum and Search --> : Getting Browser and OS names & versions from user


Stinkbug
Feb 2nd, 2002, 01:28 PM
I am working on a tracking system and am having a little trouble getting the users Browser version and the OS name and version.
I have tried via JavaScript and ASP and both ways have flaws.
In JavaScript I tried:

an=navigator.appName;
av=navigator.appversion;
at=navigator.useragent;

an will return Netscape or Microsoft Internet Explorer (dont care about others yet) but av and at will only return "Undefined"... and untill I can get something other than what I am getting I cant find out how to get the OS.
In ASP I tried:

if instr(request.servervariables("HTTP_USER_AGENT"), "MSIE") then
tempArr = split(request.servervariables("HTTP_USER_AGENT"), ";", -1,1)
response.write "browser: " & temparr(1) & "<BR>"
response.write "os: " & temparr(2) & "<BR>"
elseif instr(request.servervariables("HTTP_USER_AGENT"), "4.78") then
tempArr = split(request.servervariables("HTTP_USER_AGENT"), ";", -1,1)
response.write "browser: Netscape<BR>"
tempArr = split(request.servervariables("HTTP_USER_AGENT"), "(", -1,1)
tempArr2 = split(temparr(1), ";", -1,1)
response.write "os: " & temparr2(0) & "<BR>"

end if

That will work as far as getting the IE browser & version easy but NS is alot more work (as with everything else to do with netscrap) but the getting the os is more tricky cos WinME will show as Win98 but has an extra string... and while I could all tons of code to pick out all these things I am thinking there must be a cut and dry way to do this... or someone has done it before and there is code posted somewhere... I mean, why try to reinvent the wheel when there are porches already on the road?

thanks in advance,
Michael

Vincent Puglia
Feb 3rd, 2002, 11:07 AM
Hi,

If you go to the netscape site, there is a "Ultimate Browser Sniffer" (or somesuch) script. It has code for everything you want.

As an example:
var agt=navigator.userAgent.toLowerCase();
var isMajor = parseInt(navigator.appVersion);

var isIE = (agt.indexOf("msie") != -1);
var isIE4 = (isIE && (isMajor == 4) && (agt.indexOf("msie 5.0")==-1) );
var isIE4up = (isIE && (isMajor >= 4));
var isAOL = (agt.indexOf("aol") != -1);

Vinny