js判断运行jsp页面的浏览器类型以及版本示例
人气:0
这两天做了一个判断浏览器类型和版本号的业务,记录下相关的js代码:
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) || [];
//如果需要获取浏览器版本号:match[2]
switch(match[1]){
case "msie": //ie
if (parseInt(match[2]) === 6){ //ie6
alert("ie6");
alert("暂时不支持IE7.0及以下版本浏览器,请升级您的浏览器版本!");
/https://img.qb5200.com/download-x/document.getElementById("hid").style.display = "none";
// document.getElementById("show").style.display = "block";
/https://img.qb5200.com/download-x/document.getElementById("nosee_b").style.display = "none";
}
else if (parseInt(match[2]) === 7) { //ie7
alert("ie7");
/https://img.qb5200.com/download-x/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");
/https://img.qb5200.com/download-x/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");
/https://img.qb5200.com/download-x/document.getElementById("hid").style.display = "none";
break;
default:
break;
}
}
复制代码 代码如下:
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) || [];
//如果需要获取浏览器版本号:match[2]
switch(match[1]){
case "msie": //ie
if (parseInt(match[2]) === 6){ //ie6
alert("ie6");
alert("暂时不支持IE7.0及以下版本浏览器,请升级您的浏览器版本!");
/https://img.qb5200.com/download-x/document.getElementById("hid").style.display = "none";
// document.getElementById("show").style.display = "block";
/https://img.qb5200.com/download-x/document.getElementById("nosee_b").style.display = "none";
}
else if (parseInt(match[2]) === 7) { //ie7
alert("ie7");
/https://img.qb5200.com/download-x/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");
/https://img.qb5200.com/download-x/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");
/https://img.qb5200.com/download-x/document.getElementById("hid").style.display = "none";
break;
default:
break;
}
}
加载全部内容