I fully agree with jAndy's answer you shouldn't ever need OS detection for a web application and you should rarely need browser detection (the exception being stats/analytics, of course).
I fully agree with jAndy's answer, you shouldn't ever need OS detection for a web application and you should rarely need browser detection (the exception being stats/analytics, of course). That being said, if you're insistent you need this, you can get what you need to know using the PHP function get_browser(): $browser = get_browser(); echo $browser"platform"; // -> "WinXP.
This looks great Andy, the only reason i'm doing this is to beautify my app without sacrificing performance. (text replacement services like cufon and remotely hosted fonts like typekit/webfonts have slight performance problems) – Haroldo Jun 18 '10 at 8:52 this might come in useful one day, cheers! – Haroldo Jun 18 '10 at 9:09 2 @Haroldo: I understand and fully encourage you to do as you please.
When people talk about how it's a bad idea to use browser detection, they do so in the knowledge that it is unreliable vs feature detection. For instance, checking for IE6 to use ActiveX instead of native XMLHttpRequest is a bad idea because it can be disabled in IE7/8. What your doing doesn't seem like it could do any harm, so I don't think anyone can present a real argument against it – Andy E Jun 18 '10 at 9:10.
It actually makes no sense to determine which operating system is used for a Web Application. The only thing which should be of interest, is the Browser. Even in the Browser you just have to care about what it supports and what not.In JQuery you may use the .support(), .browser() and .boxModel() methods for that purpose.
– Haroldo Jun 18 '10 at 8:47 @Haroldo I just tried a span with Calibri in both Windows 7 and its built-in Windows XP virtual machine (on which I haven't changed any settings). They look identical to me in Firefox: pekkagaiser. Com/blog/user/files/Calibri.
PNG I had to install Calibri as it doesn't ship with XP by default - but that's a different issue, and you're going to have that on Macs, Linux-based machines etc.As well. Can you show an example of how fonts are rendered differently? – Pekka Jun 18 '10 at 8:56 @Haroldo: I'm not saying there is no difference I'm just saying it makes no sense to check for that.
Looking at Windows alone has how many, 4,5, 6 different OS versions? In that different OS versions you have to care about 3-5 different browser behaviors on that platform? It should not within your scope to care about the OS.
You still can do, but its senseless as before – jAndy Jun 18 '10 at 8:59.
Well, with PHP you could use $_SERVER'HTTP_USER_AGENT'. This string contains the browser, but also the OS. Example Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729) With the "substr" function (which is faster) or an preg_match you can extract the OS from the string.
– Haroldo Jun 18 '10 at 8:55 @Haroldo: the difference is that PHP handles the matching for you, it still uses the HTTP_USER_AGENT string, but it does the heavy lifting so you don't have to. – Andy E Jun 18 '10 at 9:13 @Andy E's head: That's what I wanted to write :) – faileN Jun 18 '10 at 9:17.
Try this if(navigator. Oscpu == 'Windows NT 5.1') { ... }.
I think thats the best way to go. – Tom Jun 18 '10 at 8:40 @Tom: Not in all browsers. In IE and Chrome, you would need to parse this information out of navigator.userAgent.
– Andy E Jun 18 '10 at 8:47 Ahh right thats true. My mistake. – Tom Jun 18 '10 at 9:05.
You should perform a check on navigator. AppVersion, which contains OS version (my Win 7 become "Windows NT 6.1"): Try this on your browser address bar to see which values are returned. Javascript:alert(navigator.
AppVersion).
You could try this function OS() { var n = navigator. Oscpu; var Name = "empty"; var osName = new Array("Windows XP", "Windows Vista", "Windows 7"); var osNameAlt = new Array("Windows NT 5.1", "Windows NT 6.0", "Windows NT 6.1"); for(a=0;a Name = osNamea; break; } } } var os = new OS(); alert(os. Name); Just add the OS names to the array.
As I mentioned in a comment reply to Adam's answer, this will only work in Firefox! – Andy E Jun 18 '10 at 9:04 Didn't see the comment until now. And posted this before I knew.
– Tom Jun 18 '10 at 9:23.
You can use navigator. Platform also: var isXP = /NT 5.1/. Test(navigator.
Platform) quirksmode. Org has a great class you can use to detect the browser platform here (pasted below). I have used similar methods to conditonally include CSS on Mac platforms, as fonts can be quite different on the Mac and even break layouts with their size and spacing difference.
I did it because it was very late in the project and we need a band-aid. I'm a fan of just letting different sites look different in different browsers, as long as they remain functional and attractive. For example, I implement rounded corners using CSS only, and therefore they don't show in IE.
I think this is acceptable, but some may not (have a look at quoterobot. Com for an example - not my work by the way! ) 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;iString; var dataProp = datai. Prop; this.
VersionSearchString = datai. VersionSearch || datai. Identity; if (dataString) { if (dataString.
IndexOf(datai. SubString)! = -1) return datai.
Identity; } else if (dataProp) return datai. 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.
UserAgent, subString: "iPhone", identity: "iPhone/iPod" }, { string: navigator. Platform, subString: "Linux", identity: "Linux" } }; BrowserDetect.init().
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.