Skip to content

Instantly share code, notes, and snippets.

@joeylin
Created August 25, 2014 23:57
Show Gist options
  • Save joeylin/50e9c601a9db754719da to your computer and use it in GitHub Desktop.
Save joeylin/50e9c601a9db754719da to your computer and use it in GitHub Desktop.
浏览器检测代码
Client = (function() {
var d = {engine: {ie: 0,gecko: 0,webkit: 0,opera: 0,khtml: 0},browser: {ie: 0,firefox: 0,chrome: 0,opera: 0,safari: 0,konq: 0}};
var b = navigator.userAgent;
var c = d.engine;
var a = d.browser;
if (window.opera) {
a.version = c.version = window.opera.version();
a.opera = c.opera = parseFloat(c.version)
} else {
if (/AppleWebKit\/(\S+)/.test(b)) {
c.version = RegExp["$1"];
c.webkit = parseFloat(c.version);
if (/Chrome\/(\S+)/.test(b)) {
a.version = RegExp["$1"];
a.chrome = parseFloat(a.version)
} else {
if (/Version\/(\S+)/.test(b)) {
a.version = RegExp["$1"];
a.safari = parseFloat(a.version)
}
}
} else {
if (/KHTML\/(\S+)/.test(b) || /Konqueror\/([^;]+)/.test(b)) {
a.version = c.version = RegExp["$1"];
a.konq = c.khtml = parseFloat(c.version)
} else {
if (/rv:([^\)]+)\) Gecko\/\d{8}/.test(b)) {
c.version = RegExp["$1"];
c.gecko = parseFloat(c.version);
if (/Firefox\/(\S+)/.test(b)) {
a.version = RegExp["$1"];
a.firefox = parseFloat(a.version)
}
} else {
if (/MSIE ([^;]+)/.test(b)) {
a.version = c.version = RegExp["$1"];
a.ie = c.ie = parseFloat(c.version)
}
}
}
}
}
return d
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment