Created
July 26, 2012 02:47
-
-
Save neekey/3179960 to your computer and use it in GitHub Desktop.
获取操作系统信息
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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