1 function IsPC() { 2 var userAgentInfo = navigator.userAgent; 3 var Agents = ["Android", "iPhone", 4 "SymbianOS", "Windows Phone", 5 "iPad", "iPod"]; 6 var flag = true; 7 for (var v = 0; v < Agents.length; v++) { 8 if (userAgentInfo.indexOf(Agents[v]) > 0) { 9 flag = false; 10 break; 11 } 12 } 13 return flag; 14 } 15 16 var flag = IsPC(); 17 console.log(flag) //true为PC端,false为手机端