Jump to content

Detect OS


laPistola

Recommended Posts

this is what i have for broswer detection, it also has OS detect at the bottom but its to basic

 

var BrowserDetect = {
init: function () {
	this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
	this.version = this.searchVersion(navigator.userAgent)
		|| this.searchVersion(navigator.appVersion)
		|| "an unknown version";
	this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
	for (var i=0;i<data.length;i++)	{
		var dataString = data[i].string;
		var dataProp = data[i].prop;
		this.versionSearchString = data[i].versionSearch || data[i].identity;
		if (dataString) {
			if (dataString.indexOf(data[i].subString) != -1)
				return data[i].identity;
		}
		else if (dataProp)
			return data[i].identity;
	}
},
searchVersion: function (dataString) {
	var index = dataString.indexOf(this.versionSearchString);
	if (index == -1) return;
	return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
	{
		string: navigator.userAgent,
		subString: "Chrome",
		identity: "Chrome"
	},
	{ 	string: navigator.userAgent,
		subString: "OmniWeb",
		versionSearch: "OmniWeb/",
		identity: "OmniWeb"
	},
	{
		string: navigator.vendor,
		subString: "Apple",
		identity: "Safari",
		versionSearch: "Version"
	},
	{
		prop: window.opera,
		identity: "Opera"
	},
	{
		string: navigator.vendor,
		subString: "iCab",
		identity: "iCab"
	},
	{
		string: navigator.vendor,
		subString: "KDE",
		identity: "Konqueror"
	},
	{
		string: navigator.userAgent,
		subString: "Firefox",
		identity: "Firefox"
	},
	{
		string: navigator.vendor,
		subString: "Camino",
		identity: "Camino"
	},
	{		// for newer Netscapes (6+)
		string: navigator.userAgent,
		subString: "Netscape",
		identity: "Netscape"
	},
	{
		string: navigator.userAgent,
		subString: "MSIE",
		identity: "Explorer",
		versionSearch: "MSIE"
	},
	{
		string: navigator.userAgent,
		subString: "Gecko",
		identity: "Mozilla",
		versionSearch: "rv"
	},
	{ 		// for older Netscapes (4-)
		string: navigator.userAgent,
		subString: "Mozilla",
		identity: "Netscape",
		versionSearch: "Mozilla"
	}
],
dataOS : [
	{
		string: navigator.platform,
		subString: "Win",
		identity: "Windows"
	},
	{
		string: navigator.platform,
		subString: "Mac",
		identity: "Mac"
	},
	{
		string: navigator.platform,
		subString: "Linux",
		identity: "Linux"
	}
]

};
BrowserDetect.init();

 

im not to bothered about more details on the Mac or Linux OS but its important for the windows one to say 95,98,ME,XP,Vista

 

is there any dom nodes that will get the information i need??

Link to comment
Share on other sites

I was Googling around and found this script for you.  It's a bit lengthy but it seems to work.

 

<br />
<!--<br />
var os, ua = navigator.userAgent;<br />
if (ua.match(/Win(dows )?NT 6\.0/)) {<br />
	os = "Windows Vista";				// Windows Vista ???<br />
}<br />
else if (ua.match(/Win(dows )?NT 5\.2/)) {<br />
	os = "Windows Server 2003";			// Windows Server 2003 ???<br />
}<br />
else if (ua.match(/Win(dows )?(NT 5\.1|XP)/)) {<br />
	os = "Windows XP";				// Windows XP ???<br />
}<br />
else if (ua.match(/Win(dows)? (9x 4\.90|ME)/)) {<br />
	os = "Windows ME";				// Windows ME ???<br />
}<br />
else if (ua.match(/Win(dows )?(NT 5\.0|2000)/)) {<br />
	os = "Windows 2000";				// Windows 2000 ???<br />
}<br />
else if (ua.match(/Win(dows )?98/)) {<br />
	os = "Windows 98";				// Windows 98 ???<br />
}<br />
else if (ua.match(/Win(dows )?NT( 4\.0)?/)) {<br />
	os = "Windows NT";				// Windows NT ???<br />
}<br />
else if (ua.match(/Win(dows )?95/)) {<br />
	os = "Windows 95";				// Windows 95 ???<br />
}<br />
else if (ua.match(/Mac|PPC/)) {<br />
	os = "Mac OS";					// Macintosh ???<br />
}<br />
else if (ua.match(/Linux/)) {<br />
	os = "Linux";					// Linux ???<br />
}<br />
else if (ua.match(/(Free|Net|Open)BSD/)) {<br />
	os = RegExp.$1 + "BSD";				// BSD ????<br />
}<br />
else if (ua.match(/SunOS/)) {<br />
	os = "Solaris";					// Solaris ???<br />
}<br />
else {<br />
	os = "N/A";					// ???? OS ???<br />
}<br />
document.write(os);<br />
// --><br />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.