京东首页如何实现pc端和移动端加载不同的html的?

时间:2024-02-23 17:20:09

进入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(vari=t[e];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(o))returni.substring(o.length,i.length)}return null}vart=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);