javascript - 京東首頁(yè)如何實(shí)現(xiàn)pc端和移動(dòng)端加載不同的html的?
問(wèn)題描述
用手機(jī)瀏覽器訪問(wèn)京東 域名是http://m.jd.com用電腦訪問(wèn)的是http://www.jd.com,當(dāng)然兩個(gè)頁(yè)面也不一樣,請(qǐng)問(wèn)這個(gè)是怎么實(shí)現(xiàn)的?方便的話寫(xiě)個(gè)實(shí)例代碼,謝謝!
問(wèn)題解答
回答1:進(jìn)入www.jd.com后代碼判斷是手機(jī)的話就跳轉(zhuǎn)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
相關(guān)文章:
1. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””2. boot2docker無(wú)法啟動(dòng)3. docker-compose中volumes的問(wèn)題4. nignx - docker內(nèi)nginx 80端口被占用5. java - SSH框架中寫(xiě)分頁(yè)時(shí)service層中不能注入分頁(yè)類(lèi)6. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.7. dockerfile - 為什么docker容器啟動(dòng)不了?8. docker容器呢SSH為什么連不通呢?9. 關(guān)于docker下的nginx壓力測(cè)試10. docker images顯示的鏡像過(guò)多,狗眼被亮瞎了,怎么辦?

網(wǎng)公網(wǎng)安備