duanji5569
2012-04-20 07:55
浏览 44
已采纳

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

I want to shunt all browsers of a certain age off to their own page. What is the best method for doing this? Perhaps some JS in the header that is wrapped in :

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

Shouldn't the above send the browser to: http://example.com/unsupported-browser/ where I have a basic controller and view to handle it? Is it that simple?

图片转代码服务由CSDN问答提供 功能建议

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

 &lt;! -  [if lte IE 7]&gt; 
&lt; script type =“text / javascript”  &gt; 
 window.location =“/ unsupported-browser /”; 
&lt; / script&gt; 
&lt;![endif]  - &gt; 
   
 
 <  p>以上不应将浏览器发送到: http://example.com/unsupported-browser/我有一个基本的控制器和视图来处理它? 这很简单吗? 
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duan0504 2012-04-20 07:58
    已采纳

    Do this in php instead. Use the user_agent class and redirect to that page.

    But more importantly, why don't you allow IE users access to your site? Is it due to CSS or something else?

    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:

    As mentioned; if you want this over your entire site, run this in MY_Controller and make sure to add $this->uri->segment(1) != 'unsupported-browser' as an extra condition to avoid redirect loops.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duancenxiao0482 2013-12-11 12:52

    Download library from http://mobiledetect.net

    Put Mobile_Detect.php in to 'libraries'

    inside main controller

    public function index() {
        $this -> load -> library('Mobile_Detect');
        $detect = new Mobile_Detect();
        if ($detect->is('Chrome') || $detect->is('iOS')) {
            // whatever you wanna do here.
        }
    }
    

    Find documentation on http://dwij.co.in/mobile-os-detection-in-php-codeigniter

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题