Determine the browser type and browser

Source: Internet
Author: User

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>
 

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.