Method 1
<script type="text/javascript"> var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android devices var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios devices alert('Is Android:'+isAndroid); alert('Is iOS:'+isiOS); </script>
Method 2 (Full Check)
<script type="text/javascript"> // Determine deivces var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return { trident: u.indexOf('Trident') > -1, //IE Core presto: u.indexOf('Presto') > -1, //Opera Core webKit: u.indexOf('AppleWebKit') > -1, //App/Chrome Core gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//Firefox mobile: !!u.match(/AppleWebKit.*Mobile.*/), //Mobile devices ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //iOS devices android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //Android devices iPhone: u.indexOf('iPhone') > -1 , //Is iPhone or QQHD browser iPad: u.indexOf('iPad') > -1, //Is iPad webApp: u.indexOf('Safari') == -1, //Is web App (w/o header n footer) weixin: u.indexOf('MicroMessenger') > -1, //Is WeChat qq: u.match(/\sQQ/i) == " qq" //Is QQ }; }(), language:(navigator.browserLanguage || navigator.language).toLowerCase() } </script>
To use:
//Is IE Core
if(browser.versions.trident){ alert("is IE"); }
//Is WebKit Core
if(browser.versions.webKit){ alert("is webKit"); }
//Is Mobile
if(browser.versions.mobile||browser.versions.android||browser.versions.ios){ alert("Mobile"); }
To check language:
currentLang = navigator.language; //Determine language (except IE)
if(!currentLang){//Determine IE
currentLang = navigator.browserLanguage;
}
alert(currentLang);
Method 3
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
//alert(navigator.userAgent);
window.location.href ="iPhone.html";
} else if (/(Android)/i.test(navigator.userAgent)) {
//alert(navigator.userAgent);
window.location.href ="Android.html";
} else {
window.location.href ="pc.html";
window.close(); // Consider to close the tab.
setTimeout(myFunction, 3000);
};
<script>
function myFunction() {
alert('Hello'); // Can put some code to close the tab or do sth else.
}
</script>
– – – – –
I’m JokerM.
This post was written by me.
End
😉
Feeling well?
For China Mainland: You must be at least 16 years old to donate.
- Debit/Credit Card
- QR Payment
- PayPal
QR Payment support: Alipay and QQ Wallet.
Working on WeChat Pay and PayNow.
Currently not available.