用JS判別瀏覽器種類以及IE版本的幾種方法小結(jié)
更新時間:2011年08月02日 23:19:42 作者:
用JS判別瀏覽器種類以及IE版本的幾種方法小結(jié),需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
var isIE=!!window.ActiveXObject;
var isIE6=isIE&&!window.XMLHttpRequest;
var isIE8=isIE&&!!document.documentMode;
var isIE7=isIE&&!isIE6&&!isIE8;
if (isIE){
if (isIE6){
alert("ie6");
}else if (isIE8){
alert("ie8");
}else if (isIE7){
alert("ie7");
}
}
--------------------------------------------------------------------------------
復(fù)制代碼 代碼如下:
if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/6./i)=="6."){
alert("IE 6");
}
else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/7./i)=="7."){
alert("IE 7");
}
else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i)=="8."){
alert("IE 8");
}
else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/9./i)=="9."){
alert("IE 9");
}
--------------------------------------------------------------------------------
復(fù)制代碼 代碼如下:
if(navigator.userAgent.indexOf("Opera") != -1) {
alert('Opera');
}
else if(navigator.userAgent.indexOf("MSIE") != -1) {
alert('Internet Explorer');
}
else if(navigator.userAgent.indexOf("Firefox") != -1) {
alert('Firefox');
}
else if(navigator.userAgent.indexOf("Netscape") != -1) {
alert('Netscape');
}
else if(navigator.userAgent.indexOf("Safari") != -1) {
alert('Safari');
}
else{
alert('無法識別的瀏覽器。');
}
--------------------------------------------------------------------------------
復(fù)制代碼 代碼如下:
if(!+'\v1' && !'1'[0]){
alert("ie6或ie7")
}
相關(guān)文章
javascript使用alert實現(xiàn)一個精美的彈窗
其實最初使用alert還是一個常態(tài),包括現(xiàn)在很多B端平臺還在直接使用alert,本文主要介紹了javascript使用alert實現(xiàn)一個精美的彈窗,感興趣的可以了解一下
2023-02-02
JS實現(xiàn)的仿東京商城菜單、仿Win右鍵菜單及仿淘寶TAB特效合集
這篇文章主要介紹了JS實現(xiàn)的仿東京商城菜單、仿Win右鍵菜單及仿淘寶TAB特效合集,以實例形式較為詳細(xì)的分析了JavaScript實現(xiàn)動態(tài)添加下拉菜單及響應(yīng)鼠標(biāo)事件生成菜單等實現(xiàn)技巧,需要的朋友可以參考下
2015-09-09
ES2020讓代碼更優(yōu)美的運(yùn)算符 (?.) (??)
這篇文章主要介紹了ES2020讓代碼更優(yōu)美的運(yùn)算符 (?.) (??),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
2021-01-01 
