在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'; }