This article introduces the use of JS to determine whether the client is iOS or Android mobile terminals, sample code as follows, interested friends can refer to the next
The principle of judgment: JavaScript is the main language of front-end development, we can write JavaScript programs to determine the type and version of the browser. JavaScript can determine browser types in general there are two ways, one is based on a variety of browser-specific properties to distinguish, the other is by analyzing the browser's useragent properties to judge. In many cases, after the value is judged by the browser type, it is also necessary to judge the browser version to handle the compatibility issue, and to judge the browser version is generally only through the analysis of the browser useragent to know. Browser type ⑴ browser-specific properties ⑵ according to useragent browser version ⑴ according to useragent for mobile browser to judge 1. How to determine whether to use regular match, matching for mobile terminals navigator.useragent whether to contain strings applewebkit*****mobile Android QQ browser HD Edition Only applewebkit 2 mobile language version of the judgment use Navigator.browserlanguage can be drawn Windows Phone language version, Of course, damn it. The language version also has compatibility differences, compatible with Mozilla, and the AppleWebKit kernel browser accesses its language version, which lists navigator.language code: code as follows: < 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.*/),//Whether for mobile terminals 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 and bottom }; } (), Language: (Navigator.browserlanguage | | navigator.language). toLowerCase () } Document.writeln ("language version:" +browser.language); Document.writeln ("Whether for Mobile Terminal:" +browser.versions.mobile); Document.writeln ("iOS terminal:" +browser.versions.ios); Document.writeln ("Android Terminal:" +browser.versions.android); Document.writeln ("Whether for iphone:" + Browser.versions.iPhone); Document.writeln ("Whether the IPad:" +browser.versions.ipad); Document.writeln ( navigator.useragent); </SCRIPT>&NBSp