How do I check if the browser is running on a MAC? [closed]
As the title describes.
I need to see if the machine accessing my page is a MAC or something else
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.
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>
ref: http://www.w3schools.com/js/js_browser.asp
You are better off doing feature detection http://www.modernizr.com/
There is a very lightweight version for jQuery available Here:
http://www.stoimen.com/blog/2009/07/16/jquery-browser-and-os-detection-plugin/
精彩评论