判断使用浏览设备的类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断使用浏览设备的类型相关的知识,希望对你有一定的参考价值。
- 判断是ios还是android
if (/(iPhone|iPad|iPod|ios)/i.test(navigator.userAgent)) { //alert(navigator.userAgent); window.location.href ="iPhone.html"; } else if (/(android)/i.test(navigator.userAgent)) { //alert(navigator.userAgent); window.location.href ="Android.html"; } else { window.location.href ="pc.html"; };
- 判断是浏览器类型
//新浪weibo客户端返回1,qq客户端返回2,微信小于6.0.2版本返回3,微信大于等于6.0.2版本返回4,其它返回0
var ua = navigator.userAgent.toLowerCase(); if(ua.match(/weibo/i) == "weibo") { return 1; } else if(ua.indexOf(‘qq/‘) != -1) { return 2; } else if(ua.match(/MicroMessenger/i) == "micromessenger") { var v_weixin = ua.split(‘micromessenger‘)[1]; v_weixin = v_weixin.substring(1, 6); v_weixin = v_weixin.split(‘ ‘)[0]; if(v_weixin.split(‘.‘).length == 2) { v_weixin = v_weixin + ‘.0‘; } if(v_weixin < ‘6.0.2‘) { return 3; } else { return 4; } } else { return 0; }
- 判断是pc还是移动端
var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; if(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) { alert("您是手机登录"); } else { alert("您是电脑登录"); }
以上是关于判断使用浏览设备的类型的主要内容,如果未能解决你的问题,请参考以下文章