首页 文章

Code Igniter - 检测浏览器的最佳方式

提问于
浏览
2

我想将所有特定年龄的浏览器分流到他们自己的页面 . 这样做的最佳方法是什么?也许包含在 Headers 中的一些JS:

<!--[if lte IE 7 ]>
    <script type="text/javascript">
        window.location = "/unsupported-browser/";
    </script>
    <![endif]-->

不应该将上面的浏览器发送到:http://example.com/unsupported-browser/我在哪里有一个基本的控制器和视图来处理它?这么简单吗?

2 回答

  • 2

    在php中这样做 . 使用user_agent classredirect到该页面 .

    但更重要的是,为什么不允许IE用户访问您的网站?是由于CSS还是别的什么?

    Code:

    $this->load->helper('url');
    $this->load->library('user_agent');
    
    if ($this->agent->browser() == 'Internet Explorer' and $this->agent->version() <= 7)
        redirect('/unsupported-browser');
    

    Edit:

    如上所述;如果你想在整个站点上使用它,请在 MY_Controller 中运行此命令,并确保添加 $this->uri->segment(1) != 'unsupported-browser' 作为额外条件以避免重定向循环 .

  • 16

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

    查找http://dwij.co.in/mobile-os-detection-in-php-codeigniter上的文档

相关问题