Copy codeThe 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 );
}
Copy codeThe 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 ";
}
}