1、怎么判断是安卓还是iOS
// 获取浏览器的userAgent,并转化为小写
var ua = navigator.userAgent.toLowerCase();
// 判断是否是苹果手机,是则为true
var isIOS = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
if(isIOS){
// 苹果手机
}else{
// 安卓手机
}
2、判断iPhone X手机或iPhone X系列手机
var reg=new RegExp("iphone","gi");
if(reg.test(navigator.userAgent) && screen.width==375 && screen.height==812){
//iPhone X
}
if(reg.test(navigator.userAgent) && screen.height>=812){
//iPhone X系列
}
3、判断用户访问页面的设备
如何判断移动端设备:
(1)判断userAgent是否带有iphone字样,判断是否是iPhone产品。
(2)判断userAgent是否带有ipad字样,判断是否是iPad产品。
(3)判断userAgent是否带有ipod字样,判断是否是iPod Touch产品。
(4)判断userAgent是否带有Android字样,判断是否是Android产品。
如何判断PC端的浏览器
(1)判断userAgent是否带有iphone字样,判断是否是iPhone产品。
(2)判断userAgent是否带有ipad字样,判断是否是iPad产品。
(3)判断userAgent是否带有ipod字样,判断是否是iPod Touch产品。
(4)判断userAgent是否带有Android字样,判断是否是Android产品。
var temp=window.navigator.userAgent.toLowerCase();
if(temp.indexOf('iphone')!=-1 || temp.indexOf('ipad')!=-1 || temp.indexOf('android')!=-1){
alert('移动设备');
location.href=''; // 页面重定向 移动端的链接
}else{
// PC设备
if(temp.indexOf('triend')!==-1){
alert('ie浏览器');
}else if(temp.indexOf('opr')!==-1){
alert('opera浏览器');
}else if(temp.indexOf('chrome')!==-1){
alert('chrome 浏览器');
}else{
alert('firefox浏览器');
}
}