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

 

posted @ 2020-02-16 14:49  鸡儿er  阅读(206)  评论(0编辑  收藏  举报