A long time ago I wrote a browser to determine the browser version or phone type through the browser navigator, which describes the use of navigator to determine the browser type. Make a supplement on this article today!
Js judges the indexOf mode of Android or ios
/ / Determine the access terminal
Var browser={
Version: function(){
Var u = navigator.userAgent, app = navigator.appVersion;
Return {
Trident: u.indexOf('Trident') > -1, //IE kernel
Presto: u.indexOf('Presto') > -1, //opera kernel
webKit: u.indexOf('AppleWebKit') > -1, //Apple, Google Kernel
Gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//Firefox kernel
Mobile: !!u.match(/AppleWebKit.*Mobile.*/), //whether it is a mobile terminal
Ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios terminal
Android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android terminal or uc browser
iPhone: u.indexOf('iPhone') > -1 , //Whether it is iPhone or QQHD browser
iPad: u.indexOf('iPad') > -1, //Is it iPad?
webApp: u.indexOf('Safari') == -1, //whether the web should be the program, no head and bottom
Weixin: u.indexOf('MicroMessenger') > -1, //Whether WeChat (new in 2015-01-22)
Qq: u.match(/\sQQ/i) == "qq" //whether qq
};
}(),
Language:(navigator.browserLanguage || navigator.language).toLowerCase()
}
Instructions:
/ / Determine whether the IE kernel
If(browser.versions.trident){ alert("is IE"); }
/ / Determine whether the webKit kernel
If(browser.versions.webKit){ alert("is webKit"); }
/ / Determine whether the mobile side
If(browser.versions.mobile||browser.versions.android||browser.versions.ios){ alert("mobile"); }
Js determines the regular expression mode of Android or ios
If (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
//alert(navigator.userAgent);
//Apple
} else if (/(Android)/i.test(navigator.userAgent)) {
//alert(navigator.userAgent);
//Android
} else {
//pc end
};