JS identifies whether the browser is android or ios
- 2020-03-30 03:45:13
- OfStack
In the project, it is necessary to scan the qr code and then automatically identify whether it is android or ios system, and download for different systems.
<script type="text/javascript">
var browser = {
versions: function() {
var u = navigator.userAgent, app = navigator.appVersion;
return {//Mobile terminal browser version information
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.*/) || !!u.match(/AppleWebKit/), //Is it 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 || u.indexOf('Mac') > -1, //Whether for iPhone or QQHD browser
iPad: u.indexOf('iPad') > -1, //Whether or not the
webApp: u.indexOf('Safari') == -1 //Whether the web should be a program without a header and a bottom
};
}(),
language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
if (browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
window.location="https://itunes.apple.com/xxx";
}
else if (browser.versions.android) {
window.location="http://xxx/xxx.apk";
}
//Document.writeln (" language version: "+ browser.language);
// document.writeln(" Is it a mobile terminal: " + browser.versions.mobile);
// document.writeln(" Ios terminal: " + browser.versions.ios);
//Document.writeln (" android terminal: "+ browser.versions.android);
//Document.writeln (" iPhone: "+ browser.versions.iphone);
// document.writeln(" Whether or not the: " + browser.versions.iPad);
// document.writeln(navigator.userAgent);
</script>