Navigator and useragent Notes

Source: Internet
Author: User

About navigator with useragent note 1.Navigator notes 

The Navigator object mainly contains some information about the client browser, the Navigator object is created automatically by the JavaScript runtime engine, but there is currently no public label for the Navigator object

This object is currently supported by all browsers.

The business I am currently exposed to is the distinction between different portals based on these attributes, such as whether to differentiate between iOS and Android clients, or to distinguish between access and so on.

2.UserAgent

The UserAgent property is a read-only string that declares the value of the user agent header used by the browser to HTPP the request, and simply says that through useragent you can obtain information such as browser category, version, client operating system, and so on.

Specific display:

3. The business scenario I have encountered:
 /*  * * get OS type, * 0 Android * 1 iOS  *  */ function   Getostype () { if  (/(Android)/i.test (NA        vigator.useragent) { return  0;  else  if  (/(iphone|ipad|ipod| IOS)/i.test (navigator.useragent) { return
     1;  else   { return  2; }    }
// JS to determine whether the current environment is an environment function is_weixin () {      var ua = navigator.userAgent.toLowerCase ();       if (Ua.match (/micromessenger/i) = = "Micromessenger")           {returntrue;      Else {            returnfalse;      }}

    /*** Note: The business scenario I encountered was to put this method into the interceptor, adding this annotation to the Controller method that needed to differentiate it * @Description: TODO (judging by the user version number is the request, the version number is 0 is non-request)*/     Public intiswx (Beatcontext beat) {intUserweixinversioncode = 0; Try{String useragent= Beat.getrequest (). GetHeader ("User-agent"); if(useragent = =NULL) {Log.info ("Interceptor: Not acquired to User-agent:" +useragent); UserAgent=NewString (); }            if(Useragent.indexof ("Micromessenger") >= 0) {String weixinversion= Useragent.substring (Useragent.indexof ("Micromessenger") + 15); Weixinversion= weixinversion.substring (0, Weixinversion.indexof ("."))); Userweixinversioncode=Integer.parseint (weixinversion); }            //pass information to the next page            if(Userweixinversioncode! = 0) {Beat.getmodel (). Add ("Isweixin",true); Beat.getmodel (). Add ("Userweixinversioncode", Userweixinversioncode); } Else{Beat.getmodel (). Add ("Isweixin",false); }        } Catch(NumberFormatException e) {Beat.getmodel (). Add ("Isweixin",false); Log.error ("User version information acquisition failed", E); }        returnUserweixinversioncode; }}

 

Navigator and useragent Notes

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.