Skip to content

Instantly share code, notes, and snippets.

@neekey
Created July 26, 2012 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neekey/3179960 to your computer and use it in GitHub Desktop.
Save neekey/3179960 to your computer and use it in GitHub Desktop.
获取操作系统信息
var getOSInfo = function() {
var ua = navigator.userAgent;
// Ref: http://msdn.microsoft.com/en-us/library/ms537503%28VS.85%29.aspx
var token = [
// 顺序无关,根据占用率排列
["Windows NT 5.1", "WinXP"],
["Windows NT 6.0", "WinVista"],
["Windows NT 6.1", "Win7"],
["Windows NT 5.2", "Win2003"],
["Windows NT 5.0", "Win2000"],
["Macintosh", "Macintosh"],
["Windows","WinOther"],
["Ubuntu", "Ubuntu"],
["Linux", "Linux"]
];
for (var i = 0, len = token.length; i < len; ++i) {
if (ua.indexOf(token[i][0]) != -1) {
return token[i][1];
}
}
return "Other";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment