用手機瀏覽器訪問京東網域是http://m.jd.com
用電腦訪問的是http://www.jd.com,當然兩個頁面也不一樣,請問這個是怎麼實現的?
方便的話寫個實例程式碼,謝謝!
怪我咯2017-06-17 09:18:32
進入www.jd.com後代碼判斷是手機的話就跳到m.jd.com
let ua = window.navigator.userAgent.toLocaleLowerCase()
let murl ="//m.jd.com",
let reg =/iphone|android|symbianos|windows\sphone/g
if (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|windows\sphone/g,c=/micromessenger|qq\/[\d.]+/i;return c.test(e)?(n.location.href="//wqs.jd.com/?from=jdindex",!1):r.test(e)&&"1"!=t?(n.location.href=i,!1):void 0}(window);