Javascript code to get the browser version and name implementation function _ javascript skills

Source: Internet
Author: User
Obtain the browser name and version information. If the current browser is IE, the browser version is displayed. Otherwise, the current browser name and version are displayed. For detailed implementation code, see this article. The Code is as follows:


// Obtain the browser name and version information
Function appInfo (){
Var browser = {
Msie: false, firefox: false, opera: false, safari: false,
Chrome: false, netscape: false, appname: 'unknown ', version: 0
},
UserAgent = window. navigator. userAgent. toLowerCase ();
If (/(msie | firefox | opera | chrome | netscape) \ D + (\ d [\ d.] *)/. test (userAgent )){
Browser [RegExp. $1] = true;
Browser. appname = RegExp. $1;
Browser. version = RegExp. $2;
} Else if (/version \ D + (\ d [\ d.] *). * safari/. test (userAgent) {// safari
Browser. safari = true;
Browser. appname = 'safari ';
Browser. version = RegExp. $2;
}
Return browser;
}
// Call example
Var myos = appInfo ();
// If the current browser is IE, the browser version is displayed. Otherwise, the current browser name and version are displayed.
If (myos. msie ){
Alert (myos. version );
} Else {
Alert (myos. appname + myos. version );
}


The Code is as follows:


Function getOs ()
{
Var OsObject = "";
If (navigator. userAgent. indexOf ("MSIE")> 0 ){
Return "MSIE ";
}
If (isFirefox = navigator. userAgent. indexOf ("Firefox")> 0 ){
Return "Firefox ";
}
If (isSafari = navigator. userAgent. indexOf ("Safari")> 0 ){
Return "Safari ";
}
If (isCamino = navigator. userAgent. indexOf ("Camino")> 0 ){
Return "Camino ";
}
If (isMozilla = navigator. userAgent. indexOf ("Gecko/")> 0 ){
Return "Gecko ";
}
}

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.