JS判斷客戶端是手機還是PC
阿新 • • 發佈:2018-06-19
gen tin class function use nav andro inf phone
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為手機端
JS判斷客戶端是手機還是PC