Search code examples
internet-explorer-10internet-explorer-11browser-detection

How to set a different user agent for IE10 and IE11


I have a java web application running on Tomcat which works in Internet Explorer 8, and works in Internet Explorer 10 by setting the user agent string to IE8 mode. This web application mostly works in Internet Explorer 11 in IE10 mode via content="IE=10". The web application does not work in IE11 in IE8 mode due to IE11 emulation issues. Edge mode for IE11 does not work. IE10 mode is the only viable option at this stage.

I am looking for a way to set the browser mode for IE10 to emulate IE8, and set IE11 to emulate IE10 in the absence of conditional comments.

We have users with IE8, IE10 and IE11 on Windows 7. IE10 is currently the dominant browser in use. We are moving to IE11 "soon". No other browsers can be used. Users have no choice of IE version, they will be upgraded over time to IE11.

To answer the question of: "Why set IE=8 mode for IE10 and IE=10 mode for IE11?":

It may be possible to fix some of the web application code so that IE11 works in IE=10 mode. IE11 emulation for IE8 is broken to the point that it is not worth trying to fix. The vendor does not support IE11. The best I can do is set an emulation mode which works for most features and fix the rest where possible.

IE=8 is the UA mode which works for IE8 and IE10. This needs to be kept until IE10 is no longer used.

<meta http-equiv="X-UA-Compatible" content="IE=8" />

The most promising UA setting in IE11 to get this application to work is IE=10. This can not be set directly as it breaks the application for IE10 users. For IE11 alone this is a solution:

<meta http-equiv="X-UA-Compatible" content="IE=10" />

Conditional comments are no longer supported by IE10 and IE11. This means that the following code does not work. It results in IE11 having a document mode of Edge.

<!--[if IE 11]>    
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<![endif]-->

A setting of content="IE=8, IE=10" works for IE11 but not IE10.


Solution

  • With Velocity the user agent can be set differently for Internet Explorer 10 and Internet Explorer 11 by scraping the user agent then setting the mode depending on the user agent string. This works for now for Internet Explorer 10.

    #if ( $req.getHeader("User-Agent").matches('.*Trident.6.0.*')  )
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    #else
    <meta http-equiv="X-UA-Compatible" content="IE=10" />
    #end