JS get phone model and mobile OS version number

Source: Internet
Author: User

1. js to determine the iOS version number

First look at the user-agent string for IOS:

IPhone 4.3.2 System:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5
Ipone 5.1 System:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5
Ipone 5.1.1 System:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5

We can find some rules from User-agent: all contain "iPhone" keywords; contains the system version number separated by an underscore. Well, we can use these two laws to distinguish the system above iOS4.

function Gt_ios4 () {
Determine if IPhone or IPod
if ((Navigator.userAgent.match (/iphone/i) | | navigator.userAgent.match (/ipod/i))) {
Determine if the system version number is greater than 4
Return Boolean (Navigator.userAgent.match (/os [5-9]_\d[_\d]* like Mac OS x/i);
} else {
return false;
}
}

2, JS judge the mobile browser operating system and browser methods

To do the front-end development of mobile phone, but the mobile phone platform to judge. For app downloads, see Android download prompts on Android, and iOS download tips under iOS.

Today, we introduce the method of using JS to judge the mobile client platform and system platform:

<script type= "Text/javascript" >//mobile phone side to determine the platform browser and operating system platform function Checkplatform () {if (/android/i.test ( navigator.useragent)) {document.write ("This is Android ' browser."); /It is Android platform under browser}if (/(Iphone|ipad|ipod|ios)/i.test (navigator.useragent)) {document.write ("This is IOS ' browser."); /This is the iOS platform under browser}if (/linux/i.test (navigator.useragent)) {document.write ("This is Linux ' browser."); /This is the Linux platform under browser}if (/linux/i.test (navigator.platform)) {document.write ("This is the Linux operating system."); /This is the Linux operating system platform}if (/micromessenger/i.test (navigator.useragent)) {document.write ("This is Micromessenger ' browser."); /This is the platform under browser}}  $ (document). Ready (function () {    alert (navigator.platform);    Checkplatform ();  }); </script>

In here do not do PC-side operating system platform judgment, how to judge also next method, such as with document.write (Navigator.platform), you can get the operating system platform. The Win32 will be displayed under the Win32, and WIN64 will be displayed under Win64.

JS get phone model and mobile OS version number

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.