javascript - 京東首頁如何實現pc端和移動端加載不同的html的?
問題描述
用手機瀏覽器訪問京東 域名是http://m.jd.com用電腦訪問的是http://www.jd.com,當然兩個頁面也不一樣,請問這個是怎么實現的?方便的話寫個實例代碼,謝謝!
問題解答
回答1:進入www.jd.com后代碼判斷是手機的話就跳轉m.jd.com
let ua = window.navigator.userAgent.toLocaleLowerCase()let murl ='//m.jd.com',let reg =/iphone|android|symbianos|windowssphone/gif (reg .test(ua )) { window.location.href = murl }
京東源碼:
!function(n){function o(n){for(var o=n+'=',t=document.cookie.split(';'),e=0;e<t.length;e++){for(var i=t[e];' '==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(o))return i.substring(o.length,i.length)}return null}var t=o('pcm'),e=n.navigator.userAgent.toLocaleLowerCase(),i='//m.jd.com',r=/iphone|android|symbianos|windowssphone/g,c=/micromessenger|qq/[d.]+/i;return c.test(e)?(n.location.!=t?(n.location.href=i,!1):void 0}(window);回答2:
判斷下UA就好了
回答3:request.getHeader('user-agent')
回答4:userAgent
回答5:window.navigator.userAgent
相關文章:
1. javascript - node.js promise沒用2. android 如何實現如圖中的鍵盤上的公式及edittext的內容展示呢3. c++ - 如何正確的使用QWebEngineView?4. golang - 用IDE看docker源碼時的小問題5. javascript - js 寫一個正則 提取文本中的數據6. 算法 - python 給定一個正整數a和一個包含任意個正整數的 列表 b,求所有<=a 的加法組合7. yii2中restful配置好后在nginx下報404錯誤8. java - 我在用Struts2上傳文件時,報以下錯誤怎么回事?9. PHP注冊功能10. php - 注冊驗證郵箱失效后操作問題
