javascript 判断是否是PC还是手机端

function IsPC() { 

   var userAgentInfo = navigator.userAgent; 

   var Agents = new Array("Android", "Linux","iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"); 

   var flag = true; 

   for (var v = 0; v < Agents.length; v++) { 

       if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } 

   } 

   return flag; 

}


注释:

如果  flag  返回 false;     手机端  
   flag 返回 turn PC端;

if(IsPC()){

    var size =0.5,title = document.title ;

    document.querySelector('.scene_title').innerHTML=title;

    document.querySelector('.p-index').style.cssText = "position:relative;height:486px;overflow:hidden;cursor:pointer";

    

}else{

    $("#code").remove();

    $('.p-index').clone().appendTo($("body"));

    $(".phone_panel").remove();

    document.querySelector('.p-index').style.height = (document.body.clientHeight ||  document.documentElement.clientHeight )+"px"

}

 

你可能感兴趣的:(JavaScript)