我想将所有特定年龄的浏览器分流到他们自己的页面上。这样做的最佳方法是什么?也许标头中的一些JS被包装在:
<!--[if lte IE 7 ]>
<script type="text/javascript">
window.location = "/unsupported-browser/";
</script>
<![endif]-->
上述内容不应该将浏览器发送到:http://example.com/unsupported-browser/我有一个基本的控制器和视图来处理它吗?有这么简单吗?
改为在 php 中执行此操作。使用 user_agent 类并重定向到该页面。
但更重要的是,为什么不允许IE用户访问您的网站?是由于CSS还是其他原因?
法典:
$this->load->helper('url');
$this->load->library('user_agent');
if ($this->agent->browser() == 'Internet Explorer' and $this->agent->version() <= 7)
redirect('/unsupported-browser');
编辑:
如前所述;如果您希望在整个站点上执行此操作,请在MY_Controller中运行此内容,并确保添加$this->uri->segment(1) != 'unsupported-browser'
作为额外条件以避免重定向循环。
从 http://mobiledetect.net 下载库
将Mobile_Detect.php放入"库"
主控制器内部
public function index() {
$this -> load -> library('Mobile_Detect');
$detect = new Mobile_Detect();
if ($detect->is('Chrome') || $detect->is('iOS')) {
// whatever you wanna do here.
}
}
查找有关 https://dwij.net/mobile-os-detection-in-php-codeigniter 的文档