1

I trying to detect ie 7 or 6 and redirect users to the error page using the javascript bellow

 var Browser = {
        Version: function () {
            var version = 999; // we assume a sane browser
            if (navigator.appVersion.indexOf("MSIE") != -1)
            // bah, IE again, lets downgrade version number
                version = parseFloat(navigator.appVersion.split("MSIE")[1]);
            return version;
        }
    }

    if (Browser.Version() == 7 || Browser.Version() == 6) {

        if (window.location.href != "/browser_problem") {
            window.location.href = "/browser_problem";
        }
    }

I got some Feedback, that ie version 8.0.7601.17514 is redirect users to the error page like they are on ie 7 or 6.

Any idea what can be the problem?

Ian
  • 50,146
  • 13
  • 101
  • 111
baaroz
  • 19,119
  • 7
  • 37
  • 47
  • 5
    Use conditional comments. – SLaks Jun 03 '13 at 14:21
  • 7
    Don't use browser detection anyway. Use feature detection to check against failures. – Bergi Jun 03 '13 at 14:22
  • Please check this [SO answer](http://stackoverflow.com/a/13287226/1169519). – Teemu Jun 03 '13 at 14:25
  • 1
    possible duplicate of [IE10 renders in IE7 mode. How to force Standards mode?](http://stackoverflow.com/questions/13284083/ie10-renders-in-ie7-mode-how-to-force-standards-mode) – Christoph Jun 03 '13 at 14:31
  • [Here's a Q/A](http://stackoverflow.com/a/4228216/2437417) that uses conditional comments within a JavaScript program to figure out the IE version. This is reliable since conditional comments can't be spoofed. –  Jun 03 '13 at 14:32

1 Answers1

2

I assume that you got this solution from here?

If you read through the comments for the chunk of code you're using (on the link above) you'll see that someone else had the same issue you're having.

The code itself is sound (although you'll find a few people who don't feel that browser-sniffing in this fashion is good practice).

The reason Internet Explorer 8 is getting caught and redirected is either:

  • The user has their browser in IE7 compatibility mode (which is possible from the Tools menu, or the little browser icon in the URL bar - IE8 was intended to be intelligent enough to detect and switched to IE7 mode automatically. This is usually caused by invalid markup);
  • The website itself is forcing their browser into IE7-mode using X-UA-Compatible or similar.

To get to the bottom of your issues, get hold of a copy of IE8 and try it out for yourself (you can use BrowserStack - a really good in-browser resource for cross-browser testing), if you can replicate it using IE8, make sure you're not in IE7 mode in the Tools menu.

Take a look at the HTML markup on your page and ensure that you don't have an X-UA-Compatible meta-tag that looks something like this in the head:

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

Which could be changed to:

<meta http-equiv="X-UA-Compatible" content="IE=edge">
johnkavanagh
  • 4,614
  • 2
  • 25
  • 37
  • 1
    most likely he's on an intranet site that forces the IE into compat mode. You should use IE=Edge for that. – Christoph Jun 03 '13 at 14:30
  • Those `meta`s have no influence without document type declaration at the beginnig of the page. – Teemu Jun 03 '13 at 14:34
  • Thanks @Christoph you're absolutely correct. Question updated to add a little more clarity. – johnkavanagh Jun 03 '13 at 14:34
  • I am using to force ie10 to work like 9,how can I use IE=Edge? – baaroz Jun 03 '13 at 14:37
  • @baaroz - you should add the `IE-edge` line described above. In addition, ask your users to turn off the IE config setting that says "Force compat mode for intranet sites". (see Tools menu, Compatibility mode settings) – Spudley Jun 03 '13 at 14:40
  • @Spudley,but what about I need this to force ie10 to work like ie9. will IE=edge override it? – baaroz Jun 03 '13 at 14:45
  • 3
    If you *really* need to force IE10 into IE9 mode, then yesm use `IE=9`. But `edge` is preferable; if you think you need anything other than `edge`, then it indicates you probably have something else in your code that needs to be fixed, because there's nothing significant wrong in IE10 that switching to IE9 mode would fix. – Spudley Jun 03 '13 at 14:49
  • Unfortunately you are so wrong.if you know .net please read this:https://connect.microsoft.com/VisualStudio/feedback/details/755419/asp-net-4-0-and-ie10-click-on-imagebutton-in-updatepanel-produces-error-click-on-normal-button-does-not – baaroz Jun 03 '13 at 14:55