-
Notifications
You must be signed in to change notification settings - Fork 0
/
browserDetect.js
39 lines (29 loc) · 1.01 KB
/
browserDetect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Uses CSS classNames on the HTML tag to describe user agent. CSS developers use these classNames to apply
* CSS style that work around browser incompatibilities
*/
AJS.describeBrowser = function (userAgent) {
userAgent = userAgent || navigator.userAgent;
var isChrome = /chrome/.test( navigator.userAgent.toLowerCase() ),
isSafari = !isChrome&&/safari/.test( navigator.userAgent.toLowerCase() ),
match = jQuery.uaMatch(userAgent),
browser = match.browser,
version = match.version.replace(/\.0$/, ""),
classNames = [];
if (isChrome) {
classNames.push("chrome");
}
if (isSafari) {
classNames.push("safari");
}
classNames.push(browser);
if (browser === "msie") {
classNames.push(browser + "-" + version);
version = parseInt(version);
while (version > 6) {
--version;
classNames.push(browser + "-gt-" + version);
}
}
jQuery("html").addClass(classNames.join(" "));
};