在pc端页面上的判断
var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire"); var browser = navigator.userAgent.toLowerCase(); var isMobile = false; for (var i=0; i<mobileAgent.length; i++){ if (browser.indexOf(mobileAgent[i])!=-1){ isMobile = true; //alert(mobileAgent[i]); location.href = 'index-mobile.html'; break; } }
在移动端页面上的判断
var w = document.documentElement.clientWidth || document.body.clientWidth; // alert(w); if(w > 640){ location.href = 'index.html'; }
本文介绍了一种判断用户设备类型并进行页面适配的方法。通过检查用户代理字符串来识别移动设备,若为移动设备则跳转至移动端页面;在移动端页面中,根据屏幕宽度判断是否跳转至PC端页面,确保用户获得最佳浏览体验。
7893

被折叠的 条评论
为什么被折叠?



