如何屏蔽IE8及以下版本?

7
我们刚刚开发了一个Web应用程序,想要阻止Internet Explorer 8及以下版本。有什么最好的方法可以实现这一点?
我找到了一种阻止IE6的方法,但是教程(http://css-tricks.com/ie-6-blocker-script/)是从2008年的,我觉得它有点过时了。我们还想阻止IE 7和8...
该网站是使用CodeIgniter构建的,其中包含大量的Backbone.js。
如果有任何想法,将不胜感激。
谢谢!
更新
抱歉,更多信息:是的,我想要阻止它们,我想显示一条消息,并能够样式化页面以显示“对不起,您使用的是不是浏览器的Internet Explorer,请在此处下载CHROME”。

11
这是IE < 8的问题...它们已经被阻止了,因为它们无法正确地执行任何操作。不需要额外的代码。 - Colin M
@BenM 我认为他的意思是阻止使用IE < 8的人访问该网站。 - Bill
1
如果IE6阻止功能在2008年就能正常工作,那么它今天仍然可以正常工作,因为IE6自那时以来并没有改变... - Teemu
这是用于内部网络还是互联网? - cryptic ツ
1
请查看浏览器更新插件 - jbabey
显示剩余2条评论
7个回答

10
使用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(层叠样式表):
body * { display: none }
.notification { display: block; }

8

最好的方法是重定向。在客户端使用某些东西只会使当前页面变得臃肿。重定向不会执行任何不必要的JS / CSS。 - Florian Margaine

2

这是用于检查IE 8浏览器及更低版本的代码。它通常被用在<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]-->

0
您可以使用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>

或者您可以使用 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>

0

5
jQuery的browser对象在1.3版本中被弃用,在1.9版本中完全删除。 - BenM
2
文档中说:“我们建议不要使用此属性,请尝试使用特性检测(请参见jQuery.support)。jQuery.browser可能会在未来的jQuery版本中移动到插件中。”它已经在jQuery 1.9中被删除了。 - jbabey
谢谢指出。我不知道。我已经更新了回复。 - Alvaro

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

0

我相信避免与页面代码的其他部分发生冲突的最快、最安全的方法是...

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接