如何将除webkit之外的所有浏览器重定向到特定的URL?
我正在研究Apache / Htaccess,jQuery / Javascript等,但除了IE之外,我还没有找到太多东西:
<!--[if IE]>
<script type="text/javascript">
window.location = "http://www.site.net/classic/";
</script>
<![endif]-->
换句话说,如何主持一个仅限webkit的网站?
答案 0 :(得分:1)
这是jquery解决方案:
if (!$.browser.webkit) {
window.location = "http://www.site.net/classic/";
}
答案 1 :(得分:1)
对于php
方法,您可以使用$_SERVER['HTTP_USER_AGENT']
变量来确定您的用户浏览器正在使用哪个引擎,然后只显示具有webkit
引擎的页面,如下所示:
<!DOCTYPE html>
<?php
$navigator_user_agent = ' ' . strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($navigator_user_agent, "webkit")) {
?>
//Your page goes here
<?php
} else {
header('Location: www.example.com/get-webkit'); //redirects user to the given location
}
?>
即使执行上述操作,您也无法100%确定浏览器访问您网站的内容,因为有些工具可以修改浏览器引入服务器的方式,甚至包括基于cUrl的机器人,只需更改其用户 - 代理变量。