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. docker 下面創建的IMAGE 他們的 ID 一樣?這個是怎么回事????2. 在應用配置文件 app.php 中找不到’route_check_cache’配置項3. html按鍵開關如何提交我想需要的值到數據庫4. css - width設置為100%之后列表無法居中5. ios - vue-cli開發項目webstrom會在stylus樣式報錯,飆紅,請大神幫忙6. css3 - 怎么感覺用 rem 開發的不多啊7. python - 在pyqt中做微信的機器人,要在表格中顯示微信好友的名字,卻顯示不出來,怎么解決?8. html5 - 用Egret寫的小游戲,怎么分享到微信呢?9. javascript - 一個頁面有四個圖片,翻頁的時候想固定住某個圖片然后翻頁,如何實現呢?10. objective-c - 自定義導航條為類似美團的搜索欄樣式
