Home > Web Front-end > JS Tutorial > js determines the browser type and version running the jsp page_javascript skills

js determines the browser type and version running the jsp page_javascript skills

WBOY
Release: 2016-05-16 17:18:13
Original
1195 people have browsed it

In the past two days, I have done a business of determining browser type and version number, and recorded the relevant js code:

Copy code Code As follows:

function allinfo(){

var ua = navigator.userAgent;
ua = ua.toLowerCase();
var match = /(webkit) [ /]([w.] )/.exec(ua) ||
/(opera)(?:.*version)?[ /]([w.] )/.exec(ua) ||
/(msie) ([w.] )/.exec(ua) ||
!/compatible/.test(ua) && /(mozilla)(?:.*? rv:([w.] ))?/.exec(ua) || [];

//If you need to get the browser version number: match[2]

switch(match[1]){
case "msie": //ie
if (parseInt(match[2]) === 6){ //ie6
alert("ie6");
alert("IE7 is not supported at the moment .0 and below browsers, please upgrade your browser version! ");
//document.getElementById("hid").style.display = "none";
// document.getElementById( "show").style.display = "block";
//document.getElementById("nosee_b").style.display = "none";
}
else if (parseInt(match[2 ]) === 7) { //ie7
alert("ie7");
//document.getElementById("hid").style.display = "none";
// document. getElementById("show").style.display = "block";
}
else if (parseInt(match[2]) === 8){ //ie8
alert("ie8") ;
}
else if(parseInt(match[2]) === 9){
alert("ie9");
//document.getElementById("hid").style. display = "none";
}
break;
case "webkit": //safari or chrome
//alert("safari or chrome");
// document.getElementById ("middle").style.display = "none";
break;
case "opera": //opera
alert("opera");
break;
case " mozilla": //Firefox
alert("Firefox");
//document.getElementById("hid").style.display = "none";
break;
default:
break;
}
}
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