The user agent Chinese name is the users proxy, is part of the HTTP protocol, is part of the header domain, the user agent is also referred to as UA. It is a special string header that provides access to the Web site with information such as the type and version of the browser you are using, the operating system and version, the browser kernel, and so on.
Through this logo, users visit the site can display a different layout to provide users with better experience or information statistics, such as mobile phone access to Google and computer access is not the same, these are Google according to the visitor's UA to judge. The UA can also be disguised.
1 functionIsipad (useragent) {2 return(Useragent.indexof ("IPad") >-1);3 }4 functionIsiphone (useragent) {5 return(Useragent.indexof ("IPhone") >-1);6 }7 functionIsios (useragent) {8 returnIsipad (useragent) | |Isiphone (useragent);9 }Ten functionisandroid (useragent) { One return(Useragent.indexof ("Android") >-1) | | A(Useragent.indexof ("Linux") >-1); -}
The UserAgent property of the Navigator object is called by the BOM, and the device type of the mobile client can be judged based on the obtained Mobios.
Encapsulated code slices:
1 // User agent string from navigator 2 var useragent = navigator.useragent; 3 4 // Name of Mobile OS 5 var mobios = isandroid (useragent)? "Android" :6 (Isios (useragent)? "ios": "Unknow");
According to UserAgent, is the mobile end iOS or Android?