我使用PHP和HTML构建网站。如果用户使用IE浏览我的网站,我想显示一条消息:“请使用Firefox或Google Chrome”,而不是呈现索引页。
有可能吗?如果是这样,怎么办呢?
请注意我不是那么先进的PHP。
感谢。
答案 0 :(得分:2)
你也可以这样做:
<?php
function using_ie(){
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$ub =false;
if(preg_match('/MSIE/i',$user_agent))
{$ub = true;}
return $ub;
}
if(using_ie()==true){
//Show notice
}else{
//Cont
}
?>
不要忘记,IE用户仍然拥有30%的市场份额,这意味着您的用户中有1个将使用IE http://www.w3counter.com/globalstats.php
答案 1 :(得分:2)
我会给你最好的答案
在<head>
<!--[if IE]>
<script>
alert("Here you can write the warning box like this website is not supported by IE");
</script>
<script type="text/javascript">
window.location = "insert here the link of the webpage you want to redirect the users after clicking ok";
</script>
<![endif]-->
&#13;
答案 2 :(得分:1)
您可以使用Conditional Comments which are documented by the browser vendor (Microsoft)执行此操作。
通过这些,您可以让IE用户可以访问隐藏在其他所有标准兼容浏览器中的评论中的HTML,例如下载其他浏览器的消息。您甚至可以完全隐藏页面的其余部分。
答案 3 :(得分:1)
这是可能的,但我只是想告诉你,这对问题来说真的不是一个很好的解决方案。它的方式是:
$browserinfo = get_browser();
$browser = $browserinfo['browser']
if ($browser == "Internet Explorer" || $browser == "InternetExplorer" || $browser == "IE") {
include("path/to/your/errorMessage.php");
exit(0);
}
这确实需要browscap。另一种选择是:
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = false;
if(preg_match('/MSIE/i',$u_agent))
{
include("path/to/your/errorMessage.php");
exit(0);
}
答案 4 :(得分:0)
请按照此处的说明检查用户代理 http://icfun.blogspot.de/2008/07/php-how-to-check-useragent.html
我希望这是你正在寻找的东西; - )