使用navigator.userAgent.toLowerCase()判断浏览器的类型

navigator是HTML中的内置对象,包含浏览器的信息;userAgent是navigator的属性方法,可以返回由客户机发送服务器的头部的值,作用其实就是就是返回当前用户所使用的是什么浏览器,toLowerCase()是将转换为小写。

区分安卓和IOS设备

var ua = navigator.userAgent.toLowerCase();
if (/android|adr/gi.test(ua)) {
// 安卓

}else if(/(i[^;]+;( U;)? CPU.+Mac OS X/gi.test(ua)){
//苹果

}else if(/iPad/gi.test(ua)){
//ipad
}

更多请查阅
https://blog.csdn.net/AmberWu/article/details/52778530

猜你喜欢

转载自blog.csdn.net/weixin_34234721/article/details/87603481