Created
August 25, 2014 23:57
-
-
Save joeylin/50e9c601a9db754719da 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
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