The first: 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; var isandroid = u.indexof (' Android ') >-1 | | U.indexof (' Adr ') >-1; Android Terminal var Isios =!! U.match (/\ (i[^;] +;( U;)? Cpu.+mac OS x/); iOS endpoint alert (' is Android: ' +isandroid '); Alert (' iOS: ' +isios ');</script>
The second type: check whether mobile, ipad, iphone, QQ, etc.
<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 kernel Webki T: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 (' Adr ') >-1,//android terminal iphone:u.indexof (' iphone ') >-1,//whether for IPhone or Qqhd browser ipad:u.indexof (' ipad ') >-1,//whether the IPad webapp:u.indexof (' Safari ') = = 1,//whether the Web should program, no head with the bottom weixin:u.indexof (' Micromessen Ger ') >-1,//whether (2015-01-22 new) Qq:u.match (/\sqq/i) = = "QQ"//Whether QQ}; } (), Language: (Navigator.browserlanguage | | navigator.language). toLowerCase ()}</script>
How to use:
Determine if IE kernel if (browser.versions.trident) {alert ("is IE");}//Determine if webKit kernel if (browser.versions.webKit) {alert ("is WebKit "); }//Determine if the moving End if (browser.versions.mobile| | browser.versions.android| | Browser.versions.ios) {alert ("mobile Side");}
Detecting Browser language
Currentlang = Navigator.language; Determine whether other browsers use the language if (!currentlang) {///To determine the use of the language Currentlang = navigator.browserlanguage;} alert (Currentlang) in addition to IE;
The Third Kind: Judge iphone|ipad|ipod|ios| Android client, from http://www.fufuok.com/JS-iphone-android.html
if (/(Iphone|ipad|ipod|ios)/i.test (navigator.useragent)) {//Judgment Iphone|ipad|ipod|ios //alert ( navigator.useragent); Window.location.href = "iphone.html";} else if (/(Android)/i.test (navigator.useragent)) { //Judge Android //alert (navigator.useragent); Window.location.href = "android.html";} else {//pc window.location.href = "pc.html";};
The fourth kind: Judge PC or mobile
<script>//Determine if the mobile-side access var useragentinfo = Navigator.userAgent.toLowerCase (); var Agents = ["Android", "iphone", "SymbianOS", "Windows Phone", "ipad", "ipod"); var ly=document.referrer; Returns the URL for the page that contains the hyperlink that navigates to the current Web page for (var v = 0; v < agents.length; v++) { if (Useragentinfo.indexof (Agents[v]) >= 0&& (ly== "" | | Ly==null) { this.location.href= ' http://m.***.com ';//wap-side address } }</script>
JS a variety of ways to judge Android, iOS, or browsers (four methods)