Rajeev Menon
Rajeev Menon

Reputation: 294

Internet explorer 11 - How to set user agent string using code (Not the document mode)

I am trying to fix several web pages originally designed for older versions of internet explorer to render fine on internet explorer 11. With the following meta tag, the page looks almost okay but still one part of the page is broken.

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

While checking in the debugger tool, I see that the document mode is correctly set to 9. But the user agent string is showing as Default. When I change the user agent string to Internet Explorer 9 using the debugger tool, the page renders as I want.

I did a lot of research to find how I can set the user agent string using code or the doctype directive and so far no luck. At this point, I almost think that it is not possible to set the user agent string using code in IE11.

To summarize, what I am trying to do is to set the document type to "9" and the user agent string to "internet explorer 9" using code.

Upvotes: 1

Views: 5047

Answers (1)

Lance Leonard
Lance Leonard

Reputation: 3285

IE11 does not expose a public API for changing the IE user agent string using JavaScript. (You can temporarily change the user agent string using F12 tools.)

There is a set of registry settings that used to affect the navigator.userAgent property, however, these settings are no longer used during the HTTP negotiation process. (Also, it's probably worth pointing out that the version vectors mentioned in this article require conditional comments which became unsupported starting with IE10.)

The user agent string has become an increasingly difficult feature to rely on. Solutions requiring specific user agent strings should be updated to rely on more modern approaches.

You should take a look at the legacy code and look for the part that's sniffing the user-agent string. It's possible you might be able to fix it with only minor surgery.

Hope this helps...

-- Lance

Upvotes: 1

Related Questions