0

I'm creating a website with Zepto, so it doesn't support any Internet Explorer version.

How can I detect if a user is using Internet Explorer and redirect them to a page informing that the website doesn't support IE?

I've read about conditional comments, but them aren't supported in Internet Explorer 10.

Thanks.

swayziak
  • 353
  • 2
  • 7
  • 22

2 Answers2

0

You can never know for sure, but an easy option is to look at the user-agent (in e.g. PHP).

Also take a look here: How to display browser specific HTML?

Community
  • 1
  • 1
Jochem Kuijpers
  • 1,770
  • 3
  • 17
  • 34
0

Setup the document like this:

<!doctype html>
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
<head>

For IE10 use this:

    if (Function('/*@cc_on return document.documentMode===10@*/')()
){    
document.documentElement.className+=' ie10'; 
}

Then, what you do with these classes depends on whether you want to just show/hide a div with css, or use javascript to redirect the page.

Javascript:

(function ($) {
    "use strict";

    // Detecting IE
    var IE;
    if ($('html').is('.ie6, .ie7, .ie8, .ie9, .ie10')) {
        IE = true;
    }

    if (IE) {
        // redirect
       window.location.replace('http://www.myotherpage.com');
    } 

}(jQuery));

OR CSS:

.ie6 .myDivClassName,
.ie7 .myDivClassName,
.ie8 .myDivClassName,
.ie9 .myDivClassName,
.ie10 .myDivClassName {
  display: block; 
}

Depends on what you are trying to do.

redconservatory
  • 21,438
  • 40
  • 120
  • 189
  • Thanks, but what about the IE10? – swayziak Sep 28 '13 at 17:17
  • Sorry was in the middle of editing my answer when I re-read your question...IE10 you can find by using a javascript snippet, see above. – redconservatory Sep 28 '13 at 17:19
  • Thanks, but how I display another page to inform the users that the website doesn't support IE? – swayziak Sep 28 '13 at 17:45
  • window.location.replace to redirect to another page, or just have div that displays a message for IE only. See http://stackoverflow.com/questions/10964966/detect-ie-version-in-javascript – redconservatory Sep 28 '13 at 18:14
  • To IE9 and inferior I use something like this: . But where I put this div in the function that you suggest to IE10? – swayziak Sep 28 '13 at 18:24
  • Thanks. I'm going to use the CSS way because I'm using Zepto instead o jQuery. I put the if (Function('/*@cc_on return document.documentMode===10@*/')() ){ document.documentElement.className+=' ie10'; } inside a script tag before the head? – swayziak Sep 28 '13 at 19:56
  • Inside a script tag inside the head. Or in a separate .js file, your choice. – redconservatory Sep 28 '13 at 20:20
  • Thanks for the answer. I have one doubt. Where in your example do you have the myDivClassName, because I only see that in the css – swayziak Sep 29 '13 at 12:17
  • myDivClassName is the the class name of the div you happen to want to show for IE, but hide for other browsers. – redconservatory Sep 30 '13 at 12:44
  • Something like this? – swayziak Sep 30 '13 at 14:05
  • That div is not in a head tag or a body tag. It needs to be in a body tag. – redconservatory Sep 30 '13 at 14:29
  • Ok, so I put that div in the body tag, and I style the div with a "display:none", in order to hide the div when the browser isn't IE, right? – swayziak Sep 30 '13 at 15:06