Search code examples
internet-explorermeta

How do I set "user agent string" using code in IE


My applet gets loaded perfectly in IE 11 default behavior. But when I use meta tag and change it to render in IE 10, it does not load properly. Reason being meta tag has changed the document mode of IE to 10 but still the “user agent string” is pointing to IE 11. When I manually changed the “user agent string” to IE 10 it works fine again.

So is there a way where I could specify the user agent string also just like document mode in my HTML? Thanks in advance!


Solution

  • No. There is no public API for changing the IE user-agent (UA) string at run-time.

    If you use the emulation tab of F12 tools, you can temporarily change the user-agent string, but that's a temporary solution, as the UA string resets when the page refreshes.

    The UA string does change when you switch to Enterprise Mode IE, however, the result isn't entirely under your control. Because the result showcases an IE8-era UA string, it may not give you what you need.

    At one time, you could change the UA string through the Registry, but it's unclear whether that still works. (That article was first written for IE7 and was later superseded by this article.)

    Bottom line: the best way to ensure the results you're looking for is to update the solution so that it no longer relies on the user-agent sting, but instead uses feature detection or other modern approaches--a message the IE team has been advocating since the days of IE8.