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. android - webview 自定義加載進度條2. 為什么我ping不通我的docker容器呢???3. javascript - 微信小程序限制加載個數4. linux - openSUSE 上,如何使用 QQ?5. mysql - 怎么讓 SELECT 1+null 等于 16. python 怎樣用pickle保存類的實例?7. 并發模型 - python將進程池放在裝飾器里為什么不生效也沒報錯8. 大家好,請問在python腳本中怎么用virtualenv激活指定的環境?9. linux - 升級到Python3.6后GDB無法正常運行?10. Python中, 仿照經典代碼實現單例, 卻出現了不是單例的的狀態, 代碼哪里出錯了 ?
