js判斷運(yùn)行jsp頁(yè)面的瀏覽器類(lèi)型以及版本示例
更新時(shí)間:2013年10月30日 16:52:16 作者:
做了一個(gè)判斷瀏覽器類(lèi)型和版本號(hào)的業(yè)務(wù),記錄下相關(guān)的js代碼,個(gè)人感覺(jué)還不錯(cuò),需要的朋友可以參考下
這兩天做了一個(gè)判斷瀏覽器類(lèi)型和版本號(hào)的業(yè)務(wù),記錄下相關(guān)的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) || [];
//如果需要獲取瀏覽器版本號(hào):match[2]
switch(match[1]){
case "msie": //ie
if (parseInt(match[2]) === 6){ //ie6
alert("ie6");
alert("暫時(shí)不支持IE7.0及以下版本瀏覽器,請(qǐng)升級(jí)您的瀏覽器版本!");
//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;
}
}
復(fù)制代碼 代碼如下:
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) || [];
//如果需要獲取瀏覽器版本號(hào):match[2]
switch(match[1]){
case "msie": //ie
if (parseInt(match[2]) === 6){ //ie6
alert("ie6");
alert("暫時(shí)不支持IE7.0及以下版本瀏覽器,請(qǐng)升級(jí)您的瀏覽器版本!");
//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;
}
}
您可能感興趣的文章:
- JS通過(guò)分析userAgent屬性來(lái)判斷瀏覽器的類(lèi)型及版本
- js判斷當(dāng)前瀏覽器類(lèi)型,判斷IE瀏覽器方法
- JavaScript 判斷瀏覽器類(lèi)型及版本
- javascript 檢測(cè)瀏覽器類(lèi)型和版本的代碼
- js/jquery判斷瀏覽器類(lèi)型的方法小結(jié)
- javascript獲取瀏覽器類(lèi)型和版本的方法(js獲取瀏覽器版本)
- JS判斷瀏覽器類(lèi)型與版本的實(shí)現(xiàn)代碼
- javascript實(shí)現(xiàn)獲取瀏覽器版本、操作系統(tǒng)類(lèi)型
- ExtJS判斷IE瀏覽器類(lèi)型的方法
- JS如何判斷瀏覽器類(lèi)型和詳細(xì)區(qū)分IE各版本瀏覽器
相關(guān)文章
js動(dòng)態(tài)調(diào)用css屬性的小規(guī)律及實(shí)例說(shuō)明
本篇文章主要介紹了js動(dòng)態(tài)調(diào)用css屬性的小規(guī)律及實(shí)例說(shuō)明。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12js實(shí)現(xiàn)table添加行tr、刪除行tr、清空行tr的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇js實(shí)現(xiàn)table添加行tr、刪除行tr、清空行tr的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10List Information About the Binary Files Used by an Applicati
List Information About the Binary Files Used by an Application...2007-06-06webpack項(xiàng)目輕松混用css module的方法
這篇文章主要介紹了webpack項(xiàng)目輕松混用css module的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-06-06js清空表單數(shù)據(jù)的兩種方式(遍歷+reset)
這篇文章主要介紹了js清空表單數(shù)據(jù)的兩種方式(遍歷+reset),需要的朋友可以參考下2014-07-07