Skip to content

Commit 6b6da21

Browse files
committed
Simplify has("ie") detection.
Trident is set for IE8+, so I removed some legacy code that was only needed for IE6-7. Also, document.documentMode seems to be always set for IE8-11, even without an x-ua-compatible <meta> tag, but I left in code to check navigator.appVersion too, just in case it's needed for future versions of IE.
1 parent 4ad0cd7 commit 6b6da21

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

sniff.js

+7-28
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,20 @@ define(["./features"], function (has) {
3636

3737
has.add("wp", parseFloat(dua.split("Windows Phone ")[1]) || undefined);
3838

39-
4039
// Browser detection
4140
var webkit = parseFloat(dua.split("WebKit/")[1]) || undefined;
4241
if (webkit) {
4342
has.add("webkit", webkit);
4443
has.add("chrome", parseFloat(dua.split("Chrome/")[1]) || undefined);
4544
has.add("safari", dav.indexOf("Safari") >= 0 && !has("chrome") && !has("android") ?
4645
parseFloat(dav.split("Version/")[1]) : undefined);
47-
} else {
48-
var isIE = 0;
49-
if (document.all) {
50-
// IE < 11
51-
isIE = parseFloat(dav.split("MSIE ")[1]) || undefined;
52-
} else if (dav.indexOf("Trident")) {
53-
// IE >= 9
54-
isIE = parseFloat(dav.split("rv:")[1]) || undefined;
55-
}
56-
if (isIE) {
57-
// In cases where the page has an HTTP header or META tag with
58-
// X-UA-Compatible, then it is in emulation mode.
59-
// Make sure isIE reflects the desired version.
60-
// Only switch the value if documentMode's major version
61-
// is different from isIE's major version.
62-
var mode = document.documentMode;
63-
if (mode && Math.floor(isIE) !== mode) {
64-
isIE = mode;
65-
}
66-
67-
has.add("ie", isIE);
68-
} else if (dua.indexOf("Gecko") >= 0) {
69-
// Mozilla and firefox
70-
has.add("mozilla", tv);
71-
// We really need to get away from this. Consider a sane isGecko approach for the future.
72-
has.add("ff", parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1]) || undefined);
73-
}
46+
} else if (dav.indexOf("Trident") >= 0) {
47+
// IE8+
48+
has.add("ie", document.documentMode || parseFloat(dav.split("rv:")[1]));
49+
} else if (dua.indexOf("Gecko") >= 0) {
50+
// Mozilla and firefox
51+
has.add("mozilla", tv);
52+
has.add("ff", parseFloat(dua.split("Firefox/")[1] || dua.split("Minefield/")[1]) || undefined);
7453
}
7554
}
7655

tests/functional/sniff.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>

0 commit comments

Comments
 (0)