JS 识别安卓还是ios苹果、识别是否微信内置浏览器、手机类型
JS 识别安卓还是ios苹果、识别是否微信内置浏览器、手机类型
1.识别手机平台是IOS还是安卓
function ismobile ( test) {
var u = navigator. userAgent,
app = navigator. appVersion
if ( /AppleWebKit.*Mobile/i . test ( navigator. userAgent) || (
/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/
. test ( navigator. userAgent) ) ) {
if ( window. location. href. indexOf ( "?mobile" ) < 0 ) {
try {
if ( /iPhone|mac|iPod|iPad/i . test ( navigator. userAgent) ) {
return "0:苹果" ;
} else {
return "1:安桌" ;
}
} catch ( e ) {
}
}
} else if ( app. indexOf ( 'iPad' ) > - 1 || app. indexOf ( 'iPhone' ) > - 1 ) {
return "0:苹果" ;
} else {
return "1:安桌" ;
}
} ;
ismobile ( 1 )
2.识别是否微信内置浏览器
function isWeiXin ( ) {
var ua = window. navigator. userAgent. toLowerCase ( ) ;
if ( ua. match ( /MicroMessenger/i ) == 'micromessenger' ) {
return true ;
} else {
return false ;
}
}
3.识别移动终端手机品牌
function judgeBrand ( sUserAgent) {
var isHuawei = sUserAgent. match ( /huawei/i ) == "huawei" ;
var isHonor = sUserAgent. match ( /honor/i ) == "honor" ;
var isOppo = sUserAgent. match ( /oppo/i ) == "oppo" ;
var isOppoR15 = sUserAgent. match ( /pacm00/i ) == "pacm00" ;
var isVivo = sUserAgent. match ( /vivo/i ) == "vivo" ;
var isXiaomi = sUserAgent. match ( /mi\s/i ) == "mi " ;
var isXiaomi2s = sUserAgent. match ( /mix\s/i ) == "mix " ;
var isRedmi = sUserAgent. match ( /redmi/i ) == "redmi" ;
var isSamsung = sUserAgent. match ( /sm-/i ) == "sm-" ;
var isMeizu = sUserAgent. match ( /meizu/i ) == "meizu" ;
if ( isHuawei || isHonor) {
return 'huawei' ;
} else if ( isOppo || isOppoR15) {
return 'oppo' ;
} else if ( isVivo) {
return 'vivo' ;
} else if ( isXiaomi || isRedmi || isXiaomi2s) {
return 'xiaomi' ;
} else if ( isSamsung) {
return 'samsung' ;
} else if ( isMeizu) {
return 'meizu' ;
} else {
return '' ;
}
}
var brand = judgeBrand ( navigator. userAgent. toLowerCase ( ) ) ;
可关注公众号查看更多内容