Analyzing the terminal currently used by the user

In doing adaptive site, the project needs the PC display interface with the phone side display is not the same, but want to achieve in the same file, you need to determine the user's terminal, following is a judge of JS code.

 <script type="text/javascript">
// 判断是手机还是电脑打开
function IsPC(){
  var userAgentInfo = navigator.userAgent;
  var Agents = new Array("Android", "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;
  }
  if(!IsPC()){
    window.location.href = "http://m.hymba.com/index-phone.html";
  }
</script>

The above code can be realized

Guess you like

Origin blog.csdn.net/wwj791859814/article/details/73617780