我有一个使用PHP和HTML构建的网站。如果用户使用IE浏览我的网站,我想显示一条消息:“请使用Firefox或Google Chrome”,而不是呈现索引页。强制用户使用Chrome/FireFox而不是IE
可能吗?如果是这样怎么办?
请注意我不是那种先进的PHP。
谢谢。
我有一个使用PHP和HTML构建的网站。如果用户使用IE浏览我的网站,我想显示一条消息:“请使用Firefox或Google Chrome”,而不是呈现索引页。强制用户使用Chrome/FireFox而不是IE
可能吗?如果是这样怎么办?
请注意我不是那种先进的PHP。
谢谢。
你也可以做这样的:
<?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用户仍然拥有的市场份额含义1 30%的用户为3.3将使用IE http://www.w3counter.com/globalstats.php
我会将该功能放在网站标题中吗? – 2012-04-20 12:31:39
下降到[19.17%](https://www.netmarketshare.com/browser-market-share.aspx?qprid=0&qpcustomd=0) – toddmo 2017-03-26 17:28:09
这里 http://icfun.blogspot.de/2008/07/php-how-to-check-useragent.html
描述我希望这是你的寻找;-)
你可以做到这一点与Conditional Comments which are documented by the browser vendor (Microsoft)请结算的用户代理。
使用那些您可以让HTML用户访问的HTML用户隐藏在每个其他符合标准的浏览器的注释中,例如下载其他浏览器的消息。你甚至可以完全隐藏页面的其余部分。
这是可能的,但我只是想告诉你,这真的不是一个很好的解决问题的办法。它可以做到的方式是:
$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);
}
你应该提到这取决于browscap – mishu 2012-04-20 11:41:46
我会给你最好的答案
包括<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]-->
这是可能的,但很可能不令人满意的,除非你正在创建一个银行网站与用户仍然有IE6。 – Lekensteyn 2012-04-20 11:34:48
你为什么想这样做 – Toto 2012-04-20 11:35:39
@ M42 - 猜猜Sarah喜欢疏远用户。 – 2012-04-20 11:36:34