HTML and CSS Reference
In-Depth Information
On the other hand, Google and other companies opt for a JavaScript-based (also ported
to node.js ) userAgent parser internally. It's a wrapper for an approximately 7Kb JSON
file, which can be used in other languages. You can find more information at https://
github.com/Tobie/Ua-parser , but here is a snippet:
var uaParser =
require ( 'ua-parser' );
var ua = uaParser . parse ( navigator . userAgent );
console . log ( ua . tostring ());
// -> "Safari 5.0.1"
console . log ( ua . toVersionString ());
// -> "5.0.1"
console . log ( ua . toFullString ());
// -> "Safari 5.0.1/Mac OS X"
console . log ( ua . family );
// -> "Safari"
console . log ( ua . major );
// -> 5
console . log ( ua . minor );
// -> 0
console . log ( ua . patch );
// -> 1
console . log ( ua . os );
// -> Mac OS X
Another platform detection library written in JavaScript is Platform.js . It's used by
jsperf.com for userAgent detection. Platform.js has been tested in at least Adobe AIR
2.6, Chrome 5-15, Firefox 1.5-8, IE 6-10, Opera 9.25-11.52, Safari 2-5.1.1, Node.js
0.4.8-0.6.1, Narwhal 0.3.2, RingoJS 0.7-0.8, and Rhino 1.7RC3. (For more information,
see https://github.com/Bestiejs/Platform.js .)
The following example shows the results returned from various browsers when using
Platform.js :
// on IE10 x86 platform
preview running in IE7 compatibility mode on
// Windows 7 64 bit edition
platform . name ; // 'IE'
platform . version ; // '10.0'
platform . layout ; // 'Trident'
platform . os ; // 'Windows Server 2008 R2 / 7 x64'
platform . description ; // 'IE 10.0 x86 (platform preview; running in IE 7 mode) on Windows
Server 2008 R2 / 7 x64 '
Search WWH ::




Custom Search