Monday, June 3, 2024
0
rated 0 times [  5] [ 5]  / answers: 1 / hits: 85848  / 11 Years ago, wed, july 3, 2013, 12:00:00

What's the least error-prone way to target just IE11 with JavaScript?



Note: This should really only be done for analytics or informing the user what browser they're using. For everything else, there's feature detection.


More From » internet-explorer

 Answers
2

The User-agent string for IE 11 is currently this one :



Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko


Windows 10 example:



Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko


Which means your can simply test, for versions 11.xx,



var isIE11 = /Trident.*rv[ :]*11./.test(navigator.userAgent);


As IE10 user agent was



Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)


it's probably also safe to bet on the fact that now Trident/X is supposed to be the real versionning.


[#77225] Tuesday, July 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lelasamiraa

Total Points: 208
Total Questions: 99
Total Answers: 107

Location: Uzbekistan
Member since Tue, Nov 30, 2021
3 Years ago
;