夏哥事件簿 — WEB前端 — 获取设备

function IsEquipment() {
  var flag = "PC";
  var userAgentInfo = navigator.userAgent;
  var Agents = [
                "Android", 
                "iPhone", 
                "SymbianOS", 
                "Windows Phone", 
                "iPad", 
                "iPod"
                ];
  
  for (var v = 0; v < Agents.length; v++) {
    if (userAgentInfo.indexOf(Agents[v]) > 0) {
      flag = "Mobile";
      break;
    }
  }
  return flag;
}; 

获取当前设备,PC—电脑,Mobile—移动端。

你可能感兴趣的:(javascript,前端)