2

I know how to use the navigator object to find the user agent string, but Internet Explorer 11 decided to be different and go towards every other browser, saying it's Netscape.

I have to patch the issue I'm having (particularly with style sheets) but I'm wondering how, in the meantime, I can block out all versions of Internet Explorer. Period.

Here's what I have so far, but this, of course, isn't working.

window.addEventListener("load", function($) {
                    if ($.browser.msie) {window.location = 'http://google.com/chrome';}});

and of course...

            <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>

I am not looking for detection of simply Internet Explorer 11, but ALL versions of IE.

ilarsona
  • 436
  • 4
  • 13
  • possible duplicate of [Internet Explorer 11 detection](http://stackoverflow.com/questions/21825157/internet-explorer-11-detection) – Jay Feb 01 '15 at 01:19
  • There are a lot of answers in the linked question. Detecting IE11 only, all IE versions, versions upto 9, etc – Jay Feb 01 '15 at 01:20
  • $.browser was removed in jQuery 1.9. I would recommend against using it. – Jay Feb 01 '15 at 01:24
  • @JevZelenkov The code I have was from one of those answers but is not currently working. – ilarsona Feb 01 '15 at 03:32
  • does that code work for you? – Jay Feb 01 '15 at 03:35

2 Answers2

3

To detect MSIE (v6 - v7 - v8 - v9 - v10 - v11) easily:

if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
   // MSIE
}

Taken from: https://stackoverflow.com/a/22242528/975417

Community
  • 1
  • 1
Jay
  • 3,445
  • 2
  • 24
  • 29
0

This probably isn't the best way to do it, but I've gotten it to work...

    <!--[If IE]-->
    <script>
    window.addEventListener("load", function() {window.location = "http://google.com/chrome";});
</script>
    <![endif]-->
ilarsona
  • 436
  • 4
  • 13