回覆列表
  • 1 # 使用者6306467142545

    目前通用的作法是透過User-Agent判斷使用者是手機訪問還是PC訪問前端JavaScript判定:直接透過navigator.userAgent來獲取使用者代理字串,然後使用正則表示式判斷。騰訊網是這麼做的:if (window.location.toString().indexOf("pref=padindex") != -1) {} else { if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))) { if (window.location.href.indexOf("?mobile") < 0) { try { if (/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) { window.location.href = "騰訊網"; } else if (/iPad/i.test(navigator.userAgent)) { window.location.href = "騰訊首頁" } else { window.location.href = "騰訊網" } } catch(e) {} } }}後臺:後臺就是直接獲取客戶端請求頭的的User-Agent欄位,判斷的語句其實和前端差不多。

  • 2 # 使用者9364575890814

    在現在手機上網和wifi越來越普及的情況下,web網站需要對http的客戶端進行區分並適配不同的頁面,確保給使用者最合適的體驗效果。

    因此從網站伺服器端去分析,區分當前http請求是來自mobile的手機上的瀏覽器,還是來自Windows,Linux,Mac等PC電腦上的瀏覽器,就顯得非常有必要了。

  • 中秋節和大豐收的關聯?
  • C語言,從鍵盤讀入一個字串?