How to block IE8 and down?

2019-04-07 10:57发布

问题:

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".

回答1:

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)



回答2:

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; }


回答3:

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]-->


回答4:

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.



回答5:

<!--[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]-->


回答6:

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>