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

查看:185
本文介绍了javascript - 京东首页如何实现pc端和移动端加载不同的html的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

用手机浏览器访问京东 域名是http://m.jd.com
用电脑访问的是http://www.jd.com,当然两个页面也不一样,请问这个是怎么实现的?
方便的话写个实例代码,谢谢!

解决方案

进入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);

这篇关于javascript - 京东首页如何实现pc端和移动端加载不同的html的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆