简体   繁体   English

如何屏蔽IE8及以下?

[英]How to block IE8 and down?

We just finished developing a web application and we want to block Internet Explorer 8 and down.我们刚刚完成了一个 Web 应用程序的开发,我们想要阻止 Internet Explorer 8 及以下版本。 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.我找到了一种阻止 IE6 的方法,但是教程 ( http://css-tricks.com/ie-6-blocker-script/ ) 是 2008 年的,我觉得它有点过时了。 We also want to block IE 7 and 8...我们还想阻止 IE 7 和 8...

The site is built in CodeIgniter with a lot of Backbone.js.该站点是在 CodeIgniter 中构建的,其中包含大量 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".抱歉,各位,更多信息:是的,我想阻止他们,我想显示一条消息并能够将页面样式设置为“抱歉,您使用的 Internet Explorer 不是网络浏览器,请在此处下载 CHROME”。

Do it with CSS and conditional comments.使用 CSS 和条件注释来完成。

<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: CSS:

body * { display: none }
.notification { display: block; }

You can also do it with CodeIgniter, https://www.codeigniter.com/user_guide/libraries/user_agent.html您也可以使用 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 ) (也在这里回答: 代码点火器 - 检测浏览器的最佳方法

This checks for IE 8 browsers and lower.这会检查 IE 8 浏览器及更低版本。 it is used in the < head >它用于 <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]-->

You can do it using jQuery:你可以使用 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你应该看看这个: How to detection IE7 and IE8 using jQuery.support

UPDATE 2更新 2

You can also do it with PHP as pointed here.您也可以按照此处的说明使用 PHP 来完成。

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

you can use htaccess to block MSIE您可以使用 htaccess 来阻止 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 脚本

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

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM