1

I don't usually do this and do not support this approach myself. However, my current use case concerns work with MS Sharepoint, and I need to discover if a user is in any version of MSIE or not.

There does seem to be some native Sharepoint functionality that only works in MSIE but I am unable to find how it works - and of course browser sniffing is not a good approach either. I came across this snippet (reference to author at bottom) which looks like an ok test to use:

if(window.ActiveXObject || "ActiveXObject" in window){    
    // Always true if browser is Internet Explorer
}

Can anyone offer comment on the long term validity of this test. I also thought about testing if the CSS3 selector prefix '-ms-' is supported, but this will of course only work on more modern versions of IE.

Any comments/advice/suggestions much appreciated.

Reference to source of proposed solution author.

user1360809
  • 725
  • 2
  • 13
  • 24

2 Answers2

2

I suggest looking at http://browserhacks.com/ they have a list of several methods to test for IE11 and below.

Ones I personally use are,

// IE <= 10
var ieVersion = (function() { if (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null) { return parseFloat( RegExp.$1 ); } else { return false; } })();
// IE 11
var isIE = '-ms-scroll-limit' in document.documentElement.style && '-ms-ime-align' in document.documentElement.style;

ieVersion returns a number if true, false if not true. isIE evaluates to true or false

bowl0stu
  • 352
  • 1
  • 12
1

If you decide to go with a solution involving the user agent string, it's a safe bet that every IE version from 8 through 11 will include the Trident token:

/Trident/.test(navigator.userAgent)

This is the approach I'd use if I couldn't figure out what feature actually needed to be tested for.

libertyernie
  • 2,590
  • 1
  • 17
  • 13