views:

116

answers:

2

Basically I'm looking for something to give me easy access to information like useragentstring.com, but in JS, without me parsing the user agent and looking for each possible bit of text. The object could be something like this:

browser      = UserAgent.Browser;                // Chrome
browserVer   = UserAgent.BrowserVersion;         // 5.0.342.9
os           = UserAgent.OperatingSystem;        // Windows NT
osVer        = UserAgent.OperatingSystemVersion; // 6.1
layoutEng    = UserAgent.LayoutEngine;           // WebKit
layoutEngVer = UserAgent.LayoutEngineVersion;    // 533.2

Does something similar to that exist or do I have to write one myself? Writing yet another user agent parser doesn't seem that easy with all those impersonations going back to the dark ages of the web.

Specifically I'm looking for something that doesn't just split the user agent into parts and give them to me, because that's as useless as the user agent itself; instead it should parse the user agent and recognize the engine, browser, OS, etc. and return the concrete parts only, as in the example.

A: 

This should help you, have a look of the values for the following:

navigator["appCodeName"]
navigator["appName"]
navigator["appMinorVersion"]
navigator["cpuClass"]
navigator["platform"]
navigator["plugins"]
navigator["opsProfile"]
navigator["userProfile"]
navigator["systemLanguage"]
navigator["userLanguage"]
navigator["appVersion"]
navigator["userAgent"]
navigator["onLine"]
navigator["cookieEnabled"]
navigator["mimeTypes"]


<script>
   var x = '';
   for(var p in navigator)
       x += p + '=' + navigator[p] + "\n";
   alert(x);

</script>
jerjer
Unfortunately that's for from useful, as it mostly includes the same crap (literally) found in the user agent; appVersion is the user agent itself, appName is Netscate and appCodeName is Mozilla (at least on Chrome).
iconiK
+1  A: 

For more javascript oriented information see jquery.support It returns information about real browser capabilities (and drawbacks).

Requires using jQuery, but I would recommend it for almost any javascript development ;)

naugtur