In Javascript or jquery
A:
You are better off doing feature detection http://www.modernizr.com/
PetersenDidIt
2010-03-26 22:00:43
Nice link .....
Hugh
2010-03-26 22:03:23
Why the down vote? The statement is true.
PetersenDidIt
2010-03-27 19:53:19
For production code I would definitely agree with you. But that's not what the questioner asked. Maybe he is testing some code - maybe he wants to educate himself.
plodder
2010-03-27 21:46:07
The guy didn't say much so you have to guess what he is trying to do so wouldn't say this is a bad answer.
PetersenDidIt
2010-03-27 22:15:24
+1
A:
There is a very lightweight version for jQuery available Here:
http://www.stoimen.com/blog/2009/07/16/jquery-browser-and-os-detection-plugin/
Jud Stephenson
2010-03-26 22:01:00
Feature detection is better, but if you must detect the OS, the above is lightweight and works.
Jud Stephenson
2010-03-26 22:01:44
A:
You can use:
<html>
<body>
<script type="text/javascript">
document.write("Browser CodeName: " + navigator.appCodeName);
document.write("<br /><br />");
document.write("Browser Name: " + navigator.appName);
document.write("<br /><br />");
document.write("Browser Version: " + navigator.appVersion);
document.write("<br /><br />");
document.write("Cookies Enabled: " + navigator.cookieEnabled);
document.write("<br /><br />");
document.write("Platform: " + navigator.platform);
document.write("<br /><br />");
document.write("User-agent header: " + navigator.userAgent);
</script>
</body>
</html>
Hugh
2010-03-26 22:01:16
+1
A:
You could check the userAgent like this:
return navigator.userAgent.indexOf(\"Mac OS X\") != -1
But, this isn't a reliable method as it can be spoofed...but since there is no javascript absolute for this, not a terrible option. Feature detection is a better alternative if you want to see what the browser will/won't support...depends if you're after metrics of actually enabling/disabling features.
Nick Craver
2010-03-26 22:03:41