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:
context.getUserAgent().getUserAgent()
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:
- Trident/7.0 >> IE10 included Trident/6.0 and IE9 included Trident/5.0
- 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; }
