JS to determine if the client is iOS or Android

Source: Internet
Author: User

The first type: from http://blog.baiwand.com/?post=176

<script type= "Text/javascript" >//detect browser language Currentlang = navigator.language; Determine if other browsers use the language if (!currentlang) {//To determine the use of the language Currentlang = navigator.browserlanguage in IE); alert (Currentlang);//Judgment Access terminal var browser={versions:function () {var u = navigator.useragent, app = Navigator.appve        rsion; 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 the IPad webapp:u.indexof (' Safari ') = = 1,//whether the Web should program, noHead and 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 ()}//browser.versions.trident return True or false, really is the IE kernel, and so on Browser.versions.webKit is the Google kernel// 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 move End if (browser.versions.mobile| | browser.versions.android| | Browser.versions.ios) {alert ("mobile Side");} </script>

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

Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.