javascript - 京东首页如何实现pc端和移动端加载不同的html的?
问题描述
用手机浏览器访问京东 域名是http://m.jd.com用电脑访问的是http://www.jd.com,当然两个页面也不一样,请问这个是怎么实现的?方便的话写个实例代码,谢谢!
问题解答
回答1:进入www.jd.com后代码判断是手机的话就跳转m.jd.com
let ua = window.navigator.userAgent.toLocaleLowerCase()let murl ='//m.jd.com',let reg =/iphone|android|symbianos|windowssphone/gif (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|windowssphone/g,c=/micromessenger|qq/[d.]+/i;return c.test(e)?(n.location.href='https://wqs.jd.com/?from=jdindex',!1):r.test(e)&&'1'!=t?(n.location.href=i,!1):void 0}(window);回答2:
判断下UA就好了
回答3:request.getHeader('user-agent')
回答4:userAgent
回答5:window.navigator.userAgent
相关文章:
1. java - 使用 RedisTemplate 操作数据2. javascript - 如何使用nodejs 将.html 文件转化成canvas3. javascript - svg小白,想要在svg里面插入图片4. css3 - css line-height和font-size高度问题,谁能帮忙解释一下呢5. mysql - SELECT 多個資料表及多個欄位6. javascript - 粘贴一段带有图片和文字的内容,如何使用js实现获取图片并上传到服务器?7. 收缩页面显示的图片怎么写8. python - django 项目的 migrations 目录是否应该提交到 git9. css - Hexo next 主题 新增 自定义 Menus 字母怎么能首字母不自动大写?10. 怎么学好php

网公网安备