JS How to determine the user's device type and platform

Source: Internet
Author: User

Front-end development often encountered the need to determine the user's browsing device, is the PC or mobile, mobile use what mobile phone system? Android, iOS, ipad, Windows Phone, and so on, sometimes you need to know whether the user browsing page is open in the mobile browser, and so on a series of judgments to do some corresponding processing.

1, first of all to determine the PC end or mobile side.

1     functionIsPC () {2         varUseragentinfo =navigator.useragent;3         varAgents = ["Android", "IPhone",4"SymbianOS", "Windows Phone",5"IPad", "IPod"];6         varFlag =true;7          for(varv = 0; v < agents.length; v++) {8             if(Useragentinfo.indexof (agents[v]) > 0) {9Flag =false;Ten                  Break; One             } A         } -         returnFlag; -}

  

2. Determine the system platform used by the user on the mobile side

1     varU =navigator.useragent;2     if(U.indexof (' Android ') >-1 | | u.indexof (' Linux ') >-1) {3         //Android Phone4}Else if(U.indexof (' IPhone ') >-1) {5         //Apple Phone6}Else if(U.indexof (' Windows Phone ') >-1) {7         //Winphone Mobile8}

3. Determine if the user is open in

1     functionisweixin () {2         varUA =navigator.userAgent.toLowerCase ();3         if(Ua.indexof (' Micromessenger ')! =-1) { 4             return true; 5}Else { 6             return false; 7         } 8}

  

JS How to determine the user's device type and platform

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.