8

I am working on MVC application, .net 4.5 framework, VS 2010. I have a piece of Javascript code that identifies which browser the application is running. If the browser is Firefox then a particular block of code will be executed if not another block code will get executed. With IE 11 I am having a weird problem. The browser (ie 11) recognizes itself as Mozilla.

javascrip code :

 if ($.browser.mozilla) {
      if (location.pathname == "/Stats/Reports") {            // This is for local env.
      $("#prntCss").attr("href", "../../../Content/SitePrint_FF.css");
            }
            else {                                                 
      $("#prntCss").attr("href", "../../Content/SitePrint_FF.css");
      $("#rptPrntCss").attr("href", "../../Content/reportPrintStyles_FF.css");
            }

enter image description here

BumbleBee
  • 10,429
  • 20
  • 78
  • 123

4 Answers4

28

Yes. IE 11 doesnt say it is IE anymore, it says it is Mozilla.

Althoug, all IE versions respond the word Trident (its layout engine) in all of its versions.

So something like this could work in your javascript

<script type="text/javascript">
    CheckIE();
    function CheckIE()
    {
    var Browser;
    Browser = navigator.userAgent;
    if (Browser.indexOf("Trident") == -1)
    {
        //WHATHEVER YOU WANT IF IT IS NOT INTERNET EXPLORER
    }
    }
</script>
Ricardo Polo Jaramillo
  • 12,110
  • 13
  • 58
  • 83
  • Fantastic! A working solution that didn't try to tell me to use feature detection instead. Feature detection returns positive for box-shadow in IE11, but if you apply box-shadow to a tbody it puts the shadow around every cell in the table and looks awful, same as every other IE so this is exactly what I needed. – Russell Horwood Feb 25 '14 at 11:36
  • I've been impressed with what IE has done since 10, seriously good effort. But to be so obviously lame as to start wearing the cool clubs' colors and pretend to be Mozilla? That's an old school, Bill Gates Microsoft, sell at any cost, pathetic decision all the way around. How freaking embarrassing. Oh, and nice work around...but how long until MS starts carrying a Trident? – KellyCode Jul 03 '14 at 03:57
3

Yes, it does:

The compatible ("compatible") and browser ("MSIE") tokens have been removed.

...

These changes help prevent IE11 from being (incorrectly) identified as an earlier version.

Still there are some ways to detect it (search for "How to detect ie11"), but your best bet is to remove browser-detection code at all.

Andrei
  • 55,890
  • 9
  • 87
  • 108
2

This is because IE 11 has a different style of user agent strings then previous versions of IE

http://msdn.microsoft.com/library/ms537503.aspx

User-Agent: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko
Culyx
  • 529
  • 10
  • 18
2

Take a look at User agent string of IE 11: http://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx

Now it says:

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

And more details: http://www.nczonline.net/blog/2013/07/02/internet-explorer-11-dont-call-me-ie/

I think that this is the reason.

vmg
  • 9,920
  • 13
  • 61
  • 90