如何通过js判断pc访问还是手机访问

let userAgentInfo = navigator.userAgent;   
let Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone","iPad", "iPod"];  
let isPC = true;  
for (let i = 0; i < Agents.length; i++) {  
    if (userAgentInfo.indexOf(Agents[i]) > 0) {
         isPC = false; break; 
    }  
}  

if (isPC) {  
    console.log('PC访问');  
} else {  
    console.log('移动设备访问');  
}

你可能感兴趣的:(javascript,开发语言,ecmascript)