Home > Web Front-end > JS Tutorial > JS gets browser version and name implementation function_javascript skills

JS gets browser version and name implementation function_javascript skills

WBOY
Release: 2016-05-16 17:38:31
Original
950 people have browsed it
Copy code The code is as follows:

// Get 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 ( /versionD (d[d. ]*).*safari/.test( userAgent ) ){ // safari
browser.safari = true;
browser.appname = 'safari';
browser.version = RegExp.$2;
}
return browser;
}
// Calling example
var myos = appInfo();
// If the current browser is IE, pop up the browser version, otherwise pop up the current browser Device name and version
if ( myos.msie ) {
alert( myos.version );
} else {
alert( myos.appname myos.version );
}

Copy code 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";
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template