方法一:
<script type="text/javascript">
window.GLOBAL = { //浏览器版本信息
BROWSER : (function() {
var u = window.navigator.userAgent.toLocaleLowerCase(),
msie = /(msie) ([\d.]+)/,
chrome = /(chrome)\/([\d.]+)/,
firefox = /(firefox)\/([\d.]+)/,
safari = /(safari)\/([\d.]+)/,
opera = /(opera)\/([\d.]+)/,
ie11 = /(trident)\/([\d.]+)/,
b = u.match(msie)||u.match(chrome)||u.match(firefox)||u.match(safari)||u.match(opera)||u.match(ie11);
alert(b);
alert(b[1]+"-->"+parseInt(b[2]));
return {NAME: b[1], VERSION: parseInt(b[2])};
if(b[1].indexOf("trident")!="-1"){
alert("ie11浏览器");
}
if(b[1].indexOf("msie")!="-1"){
alert("ie11以下浏览器");
}
....其他浏览器以此类推
})()
}
</script>
方法二:
<script type="text/javascript">
if(navigator.userAgent.indexOf("Opera") != -1)
{
$("#headerbak").show();//提示框
//daojishi();
// document.write('您的浏览器是Opera吧?');
}else if(navigator.userAgent.indexOf("MSIE") != -1)
{
if(navigator.userAgent.indexOf("MSIE 8.0") != -1)
{
$("#headerbak").hide();
}
else if(navigator.userAgent.indexOf("MSIE 7.0") != -1)
{
$("#headerbak").show();
//daojishi();
}else if(navigator.userAgent.indexOf("MSIE 6.0") != -1)
{
$("#headerbak").show();
//daojishi();
}else{
$("#headerbak").hide();
}
}else if("ActiveXObject" in window){//MSIE X.X在ie11无效,所以单独判断
$("#headerbak").hide();
}
// 包含「Firefox」文字列
else if(navigator.userAgent.indexOf("Firefox") != -1)
{
$("#headerbak").hide();
//document.write('您的浏览器时Firefox吧?');
}
// 包含「Netscape」文字列
else if(navigator.userAgent.indexOf("Netscape") != -1)
{
$("#headerbak").hide();
//document.write('您的浏览器时Netscape吧?');
}
// 包含「Safari」文字列
else if(navigator.userAgent.indexOf("Safari") != -1)
{
$("#headerbak").hide();
//document.write('您的浏览器时Safari 吧?');
}
else{
//document.write('无法识别的浏览器。');
$("#headerbak").show();
//daojishi();
}
var sec=3;
</script>