Determine the browser type and browser
When making the front-end, you need to determine the user's browser type:
A small piece of code
Var mobileAgent = new Array ("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito ", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire ");
Var browser = navigator. userAgent. toLowerCase ();
For (var I = 0; I <mobileAgent. length; I ++ ){
If (browser. indexOf (mobileAgent [I])! =-1 ){
Flag = true;
Break
}
};
Perform operations according to the flag after the judgment is completed...
How does js determine the browser type?
<Script type = "text/javascript">
Function isIE (){
Return navigator. appName. indexOf ("Microsoft Internet Explorer ")! =-1 & document. all;
}
Function isIE6 (){
Return navigator. userAgent. split (";") [1]. toLowerCase (). indexOf ("msie 6.0") = "-1 ″? False: true;
}
Function isIE7 (){
Return navigator. userAgent. split (";") [1]. toLowerCase (). indexOf ("msie 7.0") = "-1 ″? False: true;
}
Function isIE8 (){
Return navigator. userAgent. split (";") [1]. toLowerCase (). indexOf ("msie 8.0") = "-1 ″? False: true;
}
Function isNN (){
Return navigator. userAgent. indexOf ("Netscape ")! =-1;
}
Function isOpera (){
Return navigator. appName. indexOf ("Opera ")! =-1;
}
Function isFF (){
Return navigator. userAgent. indexOf ("Firefox ")! =-1;
}
Function isChrome (){
Return navigator. userAgent. indexOf ("Chrome")>-1;
}
</Script>
The following describes how to obtain the browser information of the client using js.
The Navigator object contains information about the browser. Js obtains the browser information of the client through the attributes of Navigator.
Navigator object attributes:
Attribute
Description
AppCodeName: return the code name of the browser.
AppMinorVersion returns the secondary version of the browser.
AppName: the browser name.
AppVersion: returns the platform and version information of the browser.
BrowserLanguage returns the language of the current browser.
CookieEnabled: returns a Boolean value indicating whether the cookie is enabled in the browser.
CpuClass returns the CPU level of the browser system.
Returns a Boolean value indicating whether the system is in offline mode.
Platform returns the operating system platform that runs the browser.
SystemLanguage returns the default OS language.
UserAgent return... the remaining full text>
Script to determine the browser type
<Html>
<Body>
<Script type = "text/javascript">
If (navigator. userAgent. indexOf ("360SE")> 0 ){
Document. write ("360 browser ");
}
Else if (navigator. userAgent. indexOf ("TheWorld")> 0 ){
Document. write ("Window of the world browser ");
}
Else if (navigator. userAgent. indexOf ("Firefox")> 0 ){
Document. write ("Firefox ");
}
Else if (navigator. userAgent. indexOf ("Chrome")> 0 ){
Document. write ("Google Chrome ");
}
Else
Document. write ("other browsers ");
</Script>
</Body>
</Html>