javascript - How to load different html on the JD homepage on the PC and mobile terminals?
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-06-17 09:16:32
0
5
922

Using a mobile browser to access JD.com’s domain name is http://m.jd.com
Using a computer to access JD.com is http://www.jd.com. Of course, the two pages are different. What’s wrong with this? Realized?
Write an example code if it is convenient, thank you!

女神的闺蜜爱上我
女神的闺蜜爱上我

reply all(5)
刘奇

After entering www.jd.com, if the code determines that it is a mobile phone, it will jump to 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 
}

JD source code:

!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);
阿神

Just judgeUA

左手右手慢动作

request.getHeader("user-agent")

淡淡烟草味

userAgent

Peter_Zhu

window.navigator.userAgent

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!