判断是否是移动设备
通过user-agent值,来进行判断。使用javascript框架中的Navigator对象的userAgent属性。
/** * 判断是否是pc设备 */ function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } if(window.screen.width>=768){ flag = true; } return flag; } <script src="js/isMobile.js"></script> <script>IsPC()||(location.href="wap/index.html");</script>