簡體   English   中英

Code Igniter - 檢測瀏覽器的最佳方式

[英]Code Igniter - Best way to detect browser

我想將某個年齡的所有瀏覽器分流到他們自己的頁面。 這樣做的最佳方法是什么? 也許頭文件中的一些 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上查找文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM