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