Displaying the OS name/version and the browser name/version on the page?

Is it possible to display the OS name and version on the page with JavaScript?

I am currently using this:

function detectOSAndBrowser() {
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var nameOffset,verOffset,ix;

// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName = "Internet Explorer";
// In Chrome, the true version is after "Chrome" 
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Google Chrome";
// In Safari, the true version is after "Safari" or after "Version" 
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
// In Firefox, the true version is after "Firefox" 
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Mozilla Firefox";
// In most other browsers, "name/version" is at the end of userAgent 
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
 browserName = nAgt.substring(nameOffset,verOffset);

 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
var OSName = "unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) { 
if (navigator.appVersion.indexOf("Mac")!=-1) {
OSName="Mac OS X";
if (navigator.appVersion.indexOf("X11")!=-1) {
if (navigator.appVersion.indexOf("Linux")!=-1) {
if (OSName!=="unknown OS") {
$('#device').html('You\'re using '+browserName+'<br /><div id="OS">on a '+OSName+' computer.</div>');
if (OSName=="unknown OS") {
$('#device').html('We were unable to detect your OS and/or browser.');

It works, but I want to display the version of the OS and Browser too. This is how it looks right now when I view it:


How could I make it display the version of the browser and OS also?



It looks like Quirksmode.org is hosting a very well-thought-through script named BrowserDetect.

It has specialized search strings to extract the real version number for all major browsers.

You're using Chrome 13 on Windows!


To detect the version of the browser, you can use jQuery.browser.version.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.