Use Navigator.userAgent.toLowerCase () to determine the type of mobile end

Source: Internet
Author: User

Use Navigator.userAgent.toLowerCase () to determine the type of mobile end

Judging equipment, distinguishing between android,iphone,ipad and other

var ua   = Navigator.userAgent.toLowerCase ();   if (Ua.match (/android/i)) = = "Android")  {      alert ("Android");  }  if (Ua.match (/iphone/i)) = = "iphone")  {      alert ("iphone");  }  if (Ua.match (/ipad/i)) = = "ipad")  {      alert ("ipad");  }  

Determine whether a particular type of browser, such as Sina Weibo client built-in browser, QQ client built-in browser (not QQ browser), built-in browser

(and differentiate whether the version is greater than or equal to 6.0.2) (specific types of browsers may exist, cannot be downloaded, cannot jump and specific protocols of their own client app, etc.), so need to differentiate)

(Because of the new strategy in 6.0.2, the sharing function is different in the new version, in order to be compatible with the old and new version, there is a differentiated operation)

Sina Weibo client returns the 1,QQ client returns 2, less than 6.0.2 returns 3, greater than or equal to 6.0.2 version return 4, other return 0

var ua = Navigator.userAgent.toLowerCase ();      if (Ua.match (/weibo/i) = = "Weibo") {          return 1;      } else if (ua.indexof (' qq/')! =-1) {          return 2;      } else if (ua.match (/micromessenger/i) = = "Micromessenger") {          var v_weixin = ua.split (' Micromessenger ') [1];          V_weixin = v_weixin.substring (1,6);          V_weixin = V_weixin.split (") [0];          if (V_weixin.split ('. '). length = = 2) {              v_weixin = v_weixin + '. 0 ';          }          if (V_weixin < ' 6.0.2 ') {              return 3;          } else{              return 4;          }      } else{          return 0;      }  

  

Use Navigator.userAgent.toLowerCase () to determine the type of mobile end

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.