JS to determine whether the client is iOS or Android mobile terminals such as the method

Source: Internet
Author: User
Tags versions

  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    
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.