XSPUserAgent Methods Do Not Detect IE 11

I’ve found that the methods of the XSPUserAgent class, which are commonly used for browser detection in XPages applications, do not properly detect IE 11. In this post, I’ll show what happens and how to work around it.

Browser Detection Methods

It is standard practice to use methods like these on rendered formulas for resources (in a theme or directly on a page) that you want to conditionally load, based on the browser type:

<xp:styleSheet rendered="#{javascript:context.getUserAgent().isIE()}" href="/ie_stylesheet.css"/>
<xp:styleSheet rendered="#{javascript:context.getUserAgent().isFirefox()}" href="/firefox_stylesheet.css"/>
<xp:styleSheet rendered="#{javascript:context.getUserAgent().isChrome()}" href="/chrome_stylesheet.css"/>

Unfortunately, the isIE() check fails for IE 11.

XSPUserAgent Method Values for IE 11

Method Value Returned
context.getUserAgent().isIE() false
context.getUserAgent().getBrowser() ‘Unknown’
context.getUserAgent().getBrowserVersion() (blank)
context.getUserAgent().getBrowserVersionNumber() 0

I tested and found these return values to be the case on both 8.5.2 (which doesn’t surprise me) and Notes 9 (which does).

Checking the Full Browser String

Fortunately, this method will return the full browser string:


In IE 11, the string is as follows:

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

Apparently, Microsoft made some changes to their standard pattern for the browser string (including removing the easily-detectable ‘MSIE’).

Fortunately, two things stand out about this string:

  1. Trident/7.0 >> IE10 included Trident/6.0 and IE9 included Trident/5.0
  2. rv:11.0 >> Indicates version 11 of Internet Explorer

I don’t feel like it’s a future-proof solution, but for now, I’m checking the browser string for those values. Just in case point release numbers change, I’m checking for ‘Trident/7’ and ‘rv:11’.

Here’s a simple function that you can use to check for IE 11:

function isIE11() {
  var isBrowserIE11 = false;
  if (context.getUserAgent().getBrowser() == 'Unknown') {
    var userAgent = context.getUserAgent().getUserAgent();
    if (userAgent.indexOf('Trident/7') > -1 && userAgent.indexOf('rv:11') > -1) {
      isBrowserIE11 = true;
  return isBrowserIE11;

10 responses to “XSPUserAgent Methods Do Not Detect IE 11”

  1. Brian Moore says :

    Two options:
    1) XSPUserAgent is responding correctly – IE is not a browser.
    2) MS is so embarrassed by IE it is trying to prevent anyone from noticing when IE is actually used.

    In reality, it’s part of the general practice MS uses whenever there is a standard people rely on, they change for some reason. I suspect it it to drive more to their stack so they can say “we work with them, but they don’t work with us – you should just use use”. When that is the case because MS gets the advantage of standards but moves the goal posts – as your discovery shows.

    I think it is an exhibit of their non-collaborative culture.

  2. edm00se says :

    Excellent. This is on my horizon of “things to worry about”; so great on-topic post with the usual high class break down of what’s going on and what to do about it. Thanks Brad!

  3. Paul Hannan (@pdhannan) says :

    Great snippet Brad, thanks for sharing.
    Very useful if you really needs to know if your app is running on IE11. However it may mean that you end up having to do some extra css tweaks to your app for IE11 which are usually done through Dojo.
    This bug originated in Dojo (https://bugs.dojotoolkit.org/ticket/17311) and is fixed in the latest versions (1.9.1). But this doesn’t help Notes Domino 901 as it used Dojo 1.8.3, so obviously we’re looking to plug that gap (watch this space).
    In the meantime, use this snippet and make sure you do some extra testing of your app to see if anything is amiss.

  4. Petter Kjeilen says :

    Hi Brad. Nice snippet. You wouldn’t also have a solution for detecting if a page is displayed in Compability View mode if the Display intranet sites in Compability View setting is checked under Compability View Settings in IE (9+10) ? To me userAgent always report that page is NOT in Compability View even though it is..

    • Brad Balassaitis says :

      I don’t have code for checking whether that property is selected, but, if I’m not mistaken, you can check the browser version to see if it reports that it’s IE 8 (even if it really is 9 or 10 running in compatibility mode).

      • Petter Kjeilen says :

        I’ve put code to check for IE compat mode in my dojo.addOnLoad function.

        This does not work :
        // detect IE9 compat. mode
        if(navigator.userAgent.indexOf(“MSIE 7.0”) > 0 && navigator.userAgent.indexOf(“Trident/5.0”) > 0) {
        dojo.style(dojo.byId(‘IEcompatwarning’), “display”, “block”);

        This however works fine :
        // detect IE9 compat. mode
        var ua = “#{javascript:context.getUserAgent().getUserAgent()}”;
        if(ua.indexOf(“MSIE 7.0”) > 0 && ua.indexOf(“Trident/5.0”) > 0) {
        dojo.style(dojo.byId(‘IEcompatwarning’), “display”, “block”);

        If I do an alert of navigator.userAgent it says:
        Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.3)

        When alerting ua (context.getUserAgent().getUserAgent()) it says:
        Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.3)

        Seems to me that I cannot trust navigator.userAgent..
        context.getUserAgent().getUserAgent() is the way to go 🙂

  5. Brad Balassaitis says :

    Great info. Thanks for sharing!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: