Skip to content

Instantly share code, notes, and snippets.

@neekey
Created July 26, 2012 02:48
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/3179966 to your computer and use it in GitHub Desktop.
Save neekey/3179966 to your computer and use it in GitHub Desktop.
获取浏览器信息
var getBrowserInfo = function() {
var ua = navigator.userAgent;
// Ref: http://www.useragentstring.com/pages/useragentstring.php
var token = [ // 顺序有关
"Opera", // 某些版本会伪装成 MSIE, Firefox
"Chrome", // 某些版本会伪装成 Safari
"Safari", // 某些版本会伪装成 Firefox
"MSIE 6",
"MSIE 7",
"MSIE 8",
"Firefox"
];
for (var i = 0, len = token.length; i < len; ++i) {
if(ua.indexOf(token[i]) != -1) {
return token[i].replace(' ', '');
}
}
return "Other";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment