javascript检测客户端环境是否是pc端
1 //isPC(): 检测客户端环境是否是pc端 2 function isPC(){ 3 let userAgent = navigator.userAgent; 4 let agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; 5 let ispc = true, v; 6 for(v = 0; v < agents.length; v++){ 7 if (userAgent.indexOf(agents[v]) > 0){ispc = false; break;} 8 } 9 return ispc; 10 } 11 //调用 12 document.write(isPC());//true