Http://caibaojian.com/browser-ios-or-android.html
By judging the browser's useragent, use the regular to determine whether it is an iOS and android client. The code is as follows:
<script type="text/javascript">var u = navigator.userAgent, app = navigator.appVersion;var isAndroid = u.indexOf(‘Android‘) > -1 || u.indexOf(‘Linux‘) > -1; //android终端或者uc浏览器var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端alert(‘是否是Android:‘+isAndroid);alert(‘是否是iOS:‘+isiOS);</script>
The following is a more comprehensive browser check function, provide more check content, you can check whether it is mobile, ipad, iphone, QQ, etc.
The first type: from http://blog.baiwand.com/?post=176
<script type= "Text/javascript" >//judge Access terminal var browser={versions:function () {var u = navigator.useragent, app = Navigator.appversion; return {trident:u.indexof (' Trident ') >-1,//ie kernel presto:u.indexof (' presto ') >-1,//opera inside Nuclear webkit:u.indexof (' AppleWebKit ') >-1,//Apple, Google kernel gecko:u.indexof (' Gecko ') >-1 && u . IndexOf (' khtml ') = = -1,//Firefox core mobile:!! U.match (/applewebkit.*mobile.*/),//Whether for 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 for IPhone or Qqhd browser Ipad:u.indexof (' ipad ') >-1,//whether IPad webapp:u.indexof (' Safari ') = = 1,//whether the Web should program, no head with bottom Weixin:u.indexof (' Micromessenger ') >-1,//whether (added in 2015-01-22) qq:u.match (/\sqq/i) = = "QQ"//whether QQ }; } (), LanguAge: (Navigator.browserlanguage | | navigator.language). toLowerCase ()}</script>
How to use:
//判断是否IE内核if(browser.versions.trident){ alert("is IE"); }//判断是否webKit内核if(browser.versions.webKit){ alert("is webKit"); }//判断是否移动端if(browser.versions.mobile||browser.versions.android||browser.versions.ios){ alert("移动端"); }
Detecting Browser language
currentLang = navigator.language; //判断除IE外其他浏览器使用语言if(!currentLang){//判断IE浏览器使用语言 currentLang = navigator.browserLanguage;}alert(currentLang);
The second type: from http://www.fufuok.com/js-iphone-android. HTML
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";};
JS to determine if the client is iOS or Android