js判断移动端系统及浏览器

整理了一下移动端系统及浏览器

注:js会先判断移动端系统再判断浏览器,如果判断的系统和浏览器同级,那么他只会读取判断得到系统的信息而不是浏览器的信息;

demo演示:http://blog.retechs.cn/Browser/index.html

		
$(function(){
 toMobile();
})
function toMobile(){
  var sUserAgent = navigator.userAgent.toLowerCase();
  var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; //ipad
  var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; //苹果系统
  var bIsMidp = sUserAgent.match(/midp/i) == "midp";
  var bIsUc = sUserAgent.match(/ucbrowser/i) == "ucbrowser"; //UC浏览器
  var bIsAndroid = sUserAgent.match(/android/i) == "android"; //安卓系统
  var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; //微软掌上电脑
  var bIsQQ = sUserAgent.match(/qq/i) == "qq";//内置qq及QQ浏览器
  var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
  var bIsIE = sUserAgent.match(/iemobile/i) == "iemobile";
  var bIsWx = sUserAgent.match(/MicroMessenger/i)=="micromessenger"//微信内置浏览器
    if (bIsIpad || bIsMidp  || bIsAndroid || bIsCE || bIsWM||bIsIE) {
	alert(sUserAgent);
    }else if (bIsIphoneOs) {
     if (bIsUc) {
	alert("uc");
     }else if (bIsQQ) {
	alert("qq");
     }else if (bIsWx) {
	alert("wx");
     }
   }else{
	}
}
点赞

发表评论