您的位置:首页 > 其它

web开发中不同设备浏览器的区分

2016-01-14 12:39 246 查看
通常区分不同设备浏览器是用JavaScript中的navigator.userAgent.toLowerCase()方式获取浏览器的userAgent信息

//使用javascript判断是否是iPhone,Android或者ipad的浏览器
if ((navigator.userAgent.match(/iPhone/i))
|| (navigator.userAgent.match(/Android/i))
|| (navigator.userAgent.match(/Windows Phone/i))
|| (navigator.userAgent.match(/MQQBrowser/i))
|| (navigator.userAgent.match(/iPod/i))
|| (navigator.userAgent.match(/iPad/i))) {
  //进行相应的需要的操作
}


//判断是否用微信打开

function is_weixn() {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.match(/MicroMessenger/i) == "micromessenger") {
     window.location = "tips1.html";
  } else { //非微信中打开
    window.location = "tips2.html";
  }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: