7

We just finished developing a web application and we want to block Internet Explorer 8 and down. What is the best way to accomplish this?

I found a way to block IE6, however the tutorial (http://css-tricks.com/ie-6-blocker-script/) is from 2008 and I feel like it's a bit dated. We also want to block IE 7 and 8...

The site is built in CodeIgniter with a lot of Backbone.js.

If anyone has any ideas they would be appreciated.

Thanks!

UPDATE

Sorry guys, more information: Yes I want to BLOCK them, I want to display a message and be able to style the page to say "Sorry, you use Internet Explorer which isn't a web browser, please download CHROME here".

user1696090
  • 371
  • 2
  • 8
  • 22
  • 11
    It's IE < 8...they're already blocked by the fact that they can't do anything correctly. No additional code necessary. – Colin M Mar 07 '13 at 15:46
  • @BenM I think he means stop people in IE < 8 from accessing the site – Bill Mar 07 '13 at 15:47
  • 1
    If IE6 blocking has been working in 2008, it'll work today, IE6 hasn't change since then... – Teemu Mar 07 '13 at 15:47
  • Is this for an intranet or for the web? – kittycat Mar 07 '13 at 15:47
  • 1
    Check out [browser update plugin](http://browser-update.org/). – jbabey Mar 07 '13 at 15:51
  • Have you heard of https://developers.google.com/chrome/chrome-frame/ ? *"Google Chrome Frame is an open source plug-in that seamlessly brings Google Chrome's open web technologies and speedy JavaScript engine to Internet Explorer."* Implement it into your site strongly suggesting users of oldIE to use it. – Kevin B Mar 07 '13 at 16:16
  • I really honestly hope you aren't a business... – Rick Calder Mar 07 '13 at 17:48

7 Answers7

10

Do it with CSS and conditional comments.

<head>
    <!--[if IE lte 8]>
    <link rel="stylehseet" type="text/css" href="blockIE.css" />
    <[endif]-->
</head> 
<body>
    <div class="yourcontent">
        ...
    </div>
    <div class="notification">
        <h1>Sorry, we don't support your old browsers</h1>
    </div>
</body>

CSS:

body * { display: none }
.notification { display: block; }
Ryan Kinal
  • 17,414
  • 6
  • 46
  • 63
8

You can also do it with CodeIgniter, https://www.codeigniter.com/user_guide/libraries/user_agent.html

Something like:

$this->load->library('user_agent');
if ($this->agent->browser() == 'Internet Explorer' && $this->agent->version() <= 8){
    //Redirect or show error
}

(Also answered here: Code Igniter - Best way to detect browser)

Stack Programmer
  • 679
  • 6
  • 18
Barryvdh
  • 6,419
  • 2
  • 26
  • 23
  • Best way to do it. Using something on the client will just bloat the current page. Redirecting, no unnecessary JS/css will be executed. – Florian Margaine Mar 07 '13 at 16:06
2

This checks for IE 8 browsers and lower. it is used in the < head >

<!--[if lte IE 8]>
    <meta http-equiv="refresh" content="0; url=http://www.google.com" />
    <script type="text/javascript">
        window.top.location = 'http://www.google.com';
    </script>
<![endif]-->
Matthias Wegtun
  • 1,231
  • 1
  • 9
  • 13
0

You can do it using jQuery:

//if its internet explorer...
if(jQuery.browser.msie){
     //getting the version
     if($.browser.version < 8){
         //do whatever
     }
}

More info.

UPDATE

As the comments point, this function is not recommended. You should take a look at this: How to detect IE7 and IE8 using jQuery.support

UPDATE 2

You can also do it with PHP as pointed here.

Community
  • 1
  • 1
Alvaro
  • 40,778
  • 30
  • 164
  • 336
  • 5
    jQuery's `browser` object was deprecated in 1.3, and completely removed in 1.9. – BenM Mar 07 '13 at 15:49
  • 2
    [Docs](http://api.jquery.com/jQuery.browser/) say " We recommend against using this property; please try to use feature detection instead (see jQuery.support). jQuery.browser may be moved to a plugin in a future release of jQuery." It was removed in jQuery 1.9 – jbabey Mar 07 '13 at 15:49
  • Thanks for pointing it out. I was not aware. I updated the response. – Alvaro Mar 07 '13 at 15:52
0
<!--[if lt IE 9]>
    <!-- Some div saying sorry or calling js function or whatever -->
<![endif]-->
<!--[if lte IE 8]>
    <!-- Some div saying sorry or calling js function or whatever -->
<![endif]-->
DanielGibbs
  • 9,910
  • 11
  • 76
  • 121
Bankin
  • 777
  • 1
  • 16
  • 31
0

you can use htaccess to block MSIE

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase / 

RewriteCond %{HTTP_USER_AGENT} MSIE 
RewriteCond %{REQUEST_FILENAME} !ban_ie.php 
RewriteRule .* /ban_ie.php [L] 

RewriteCond %{HTTP_USER_AGENT} MSIE 
RewriteCond %{REQUEST_FILENAME} !ban_ie.php 
RewriteRule .* /ban_ie.php [L] 
</IfModule>

or you can use php script

<?php
ob_start();
?>
<html>
<head>
<style type="text/css">
* {
margin:0;
padding:0;
height:100%;
}
#mydiv {
position:absolute;
width:400px;
height:90px;
text-align:center;
top:50%;
left:50%;
margin-top:-40px;
margin-left:-200px;
border:solid 2px red;
padding-top:30px;
background:#ffff00;
font-weight:bold;
}
</style>
</head>
<body>
<div id="mydiv">
<?php
$browser = $_SERVER['HTTP_USER_AGENT'];
if(strstr($browser, "MSIE"))
{
   echo"BG: Свалете си Mozilla Firefox за да влезнете в сайта  EN: Download Mozilla Firefox to enter website <br /> <b><a href='http://www.mozilla.com/en-US/firefox/'>Mozilla Firefox</a></b>";
}
elseif (strstr($browser, "Opera"))
{
   echo"Свалете си мозилла <br /> <b><a href='http://www.mozilla.com/en-US/firefox/'>Mozilla Firefox</a></b>";
}
else {
   header("Location: http://muonline-bg.eu/");
}
?>
</div>
</body>
</html>
0

I believe the fastest and safest method of avoiding conflict with other parts of your page code is...

<html>
<head>
<!--[if IE lte 8]><script>location.href="my_message.html";</script><[endif]-->
<!--your other head code-->    
</head>
<body>
<!--your body code-->
</body>
</html>
Fabio
  • 229
  • 3
  • 5