Detect Exact Os Version from Browser

Detect exact OS version from browser

Short answer: You can't.

Long answer:

All you have is the information in the HTTP User-Agent header, which usually contains the OS name and version.

Usually, browsers running on Mac OS and Linux send enough information to identify the exact OS. For example, here's my User-Agent header:

Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.7) Gecko/2009030423 Ubuntu/8.10 (intrepid) Firefox/3.0.7

You can see that I'm running Ubuntu 8.10 Intrepid Ibex.

And here's what Firefox and Safari 4 Beta report on my MacBook Pro:

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.7) Gecko/2009021906 Firefox/3.0.7

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16

Windows browsers, on the other hand, usually only report the OS version and not the specific package (Pro, Business, etc.):

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:x.x.x) Gecko/20041107 Firefox/x.x

How to find the operating system details using JavaScript?

If you list all of window.navigator's properties using





console.log(navigator);

How to detect my browser version and operating system using JavaScript?

Detecting browser's details:

var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var fullVersion = ''+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
browserName = "Opera";
fullVersion = nAgt.substring(verOffset+6);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
browserName = "Microsoft Internet Explorer";
fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome"
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
browserName = "Chrome";
fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version"
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
browserName = "Safari";
fullVersion = nAgt.substring(verOffset+7);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
browserName = "Firefox";
fullVersion = nAgt.substring(verOffset+8);
}
// 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);
fullVersion = nAgt.substring(verOffset+1);
if (browserName.toLowerCase()==browserName.toUpperCase()) {
browserName = navigator.appName;
}
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1)
fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1)
fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
fullVersion = ''+parseFloat(navigator.appVersion);
majorVersion = parseInt(navigator.appVersion,10);
}

document.write(''
+'Browser name = '+browserName+'<br>'
+'Full version = '+fullVersion+'<br>'
+'Major version = '+majorVersion+'<br>'
+'navigator.appName = '+navigator.appName+'<br>'
+'navigator.userAgent = '+navigator.userAgent+'<br>'
)

Source JavaScript: browser name.

See JSFiddle to detect Browser Details.

Detecting OS:

// This script sets OSName variable as follows:
// "Windows" for all versions of Windows
// "MacOS" for all versions of Macintosh OS
// "Linux" for all versions of Linux
// "UNIX" for all other UNIX flavors
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

document.write('Your OS: '+OSName);

source JavaScript: OS detection.

See JSFiddle to detect OS Details.





    var nVer = navigator.appVersion;

var nAgt = navigator.userAgent;

var browserName = navigator.appName;

var fullVersion = ''+parseFloat(navigator.appVersion);

var majorVersion = parseInt(navigator.appVersion,10);

var nameOffset,verOffset,ix;



// In Opera, the true version is after "Opera" or after "Version"

if ((verOffset=nAgt.indexOf("Opera"))!=-1) {

browserName = "Opera";

fullVersion = nAgt.substring(verOffset+6);

if ((verOffset=nAgt.indexOf("Version"))!=-1)

fullVersion = nAgt.substring(verOffset+8);

}

// In MSIE, the true version is after "MSIE" in userAgent

else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {

browserName = "Microsoft Internet Explorer";

fullVersion = nAgt.substring(verOffset+5);

}

// In Chrome, the true version is after "Chrome"

else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {

browserName = "Chrome";

fullVersion = nAgt.substring(verOffset+7);

}

// In Safari, the true version is after "Safari" or after "Version"

else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {

browserName = "Safari";

fullVersion = nAgt.substring(verOffset+7);

if ((verOffset=nAgt.indexOf("Version"))!=-1)

fullVersion = nAgt.substring(verOffset+8);

}

// In Firefox, the true version is after "Firefox"

else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {

browserName = "Firefox";

fullVersion = nAgt.substring(verOffset+8);

}

// 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);

fullVersion = nAgt.substring(verOffset+1);

if (browserName.toLowerCase()==browserName.toUpperCase()) {

browserName = navigator.appName;

}

}

// trim the fullVersion string at semicolon/space if present

if ((ix=fullVersion.indexOf(";"))!=-1)

fullVersion=fullVersion.substring(0,ix);

if ((ix=fullVersion.indexOf(" "))!=-1)

fullVersion=fullVersion.substring(0,ix);



majorVersion = parseInt(''+fullVersion,10);

if (isNaN(majorVersion)) {

fullVersion = ''+parseFloat(navigator.appVersion);

majorVersion = parseInt(navigator.appVersion,10);

}



document.write(''

+'Browser name = '+browserName+'<br>'

+'Full version = '+fullVersion+'<br>'

+'Major version = '+majorVersion+'<br>'

+'navigator.appName = '+navigator.appName+'<br>'

+'navigator.userAgent = '+navigator.userAgent+'<br>'

)


// This script sets OSName variable as follows:

// "Windows" for all versions of Windows

// "MacOS" for all versions of Macintosh OS

// "Linux" for all versions of Linux

// "UNIX" for all other UNIX flavors

// "Unknown OS" indicates failure to detect the OS



var OSName="Unknown OS";

if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";

if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";

if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";

if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";



document.write('Your OS: '+OSName);

Detect the type of OS version in browser using javascript


var v = navigator.userAgent.match(/Mac OS X ([\d_]+)/)
if(v!=null && v[1] == "10_8_2") {
alert("U r not support!");
}

How can you detect the version of a browser?

You can see what the browser says, and use that information for logging or testing multiple browsers.





navigator.sayswho= (function(){
var ua= navigator.userAgent;
var tem;
var M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1])){
tem= /\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE '+(tem[1] || '');
}
if(M[1]=== 'Chrome'){
tem= ua.match(/\b(OPR|Edge)\/(\d+)/);
if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
}
M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]);
return M.join(' ');
})();

console.log(navigator.sayswho); // outputs: `Chrome 62`

How to get exact browser name and version?

Use get_browser()

From Manual:

echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
print_r($browser);

Will return:

Array
(
[browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
[browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*/
[parent] => Firefox 0.9
[platform] => WinXP
[browser] => Firefox
[version] => 0.9
[majorver] => 0
[minorver] => 9
[cssversion] => 2
[frames] => 1
[iframes] => 1
[tables] => 1
[cookies] => 1
[backgroundsounds] =>
[vbscript] =>
[javascript] => 1
[javaapplets] => 1
[activexcontrols] =>
[cdf] =>
[aol] =>
[beta] => 1
[win16] =>
[crawler] =>
[stripper] =>
[wap] =>
[netclr] =>
)

Any php code to detect the browser with version and operating system?

I used the techpatterns.com one and they don't always update it and it use procedural code which feel dated...

The Wolfcast BrowserDetection PHP class is updated and use an Object-Oriented way to do it:

You use it this way:

$browser = new BrowserDetection();
echo 'You are using ', $browser->getBrowser(), ' version ', $browser->getVersion();

Another example:

$browser = new BrowserDetection();
if ($browser->getBrowser() == BrowserDetection::BROWSER_FIREFOX && $browser->compareVersions($browser->getVersion(), '5.0.1') !== 1) {
echo 'You have FireFox version 5.0.1 or greater. ';
}

How can I check the operating system from website viewers?

You can not accurately determine the exact OS, but you can get the User-Agent provided by the browser. Flask will parse this into an object in request.user_agent.

from flask import request

request.headers.get('User-Agent')

jQuery - detecting the operating system and operating system version

Your best bet is to use the navigator.userAgent property. It will give the windows version number. You can see a table of how the Windows version number map to the OS here:

OSVERSIONINFO

Here is some example detection code:

var os = (function() {
var ua = navigator.userAgent.toLowerCase();
return {
isWin2K: /windows nt 5.0/.test(ua),
isXP: /windows nt 5.1/.test(ua),
isVista: /windows nt 6.0/.test(ua),
isWin7: /windows nt 6.1/.test(ua),
isWin8: /windows nt 6.2/.test(ua),
isWin81: /windows nt 6.3/.test(ua)
};
}());

if(os.isWin7) {
...
}

http://jsfiddle.net/45jEc/



Related Topics



Leave a reply



Submit