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!
怪我咯2017-06-17 09:18:32
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);