判斷瀏覽器類型,判斷瀏覽器
做前端時,需判斷使用者瀏覽器類型:
一段小小代碼
var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
var browser = navigator.userAgent.toLowerCase();
for (var i = 0; i < mobileAgent.length; i++) {
if (browser.indexOf(mobileAgent[i]) != -1) {
flag= true;
break
}
};
判斷結束後 根據flag 進行相應的操作。。。
js怎判斷瀏覽器類型
<script type=“text/javascript”>
function isIE(){
return navigator.appName.indexOf(“Microsoft Internet Explorer”)!=-1 && document.all;
}
function isIE6() {
return navigator.userAgent.split(“;”)[1].toLowerCase().indexOf(“msie 6.0″)==“-1″?false:true;
}
function isIE7(){
return navigator.userAgent.split(“;”)[1].toLowerCase().indexOf(“msie 7.0″)==“-1″?false:true;
}
function isIE8(){
return navigator.userAgent.split(“;”)[1].toLowerCase().indexOf(“msie 8.0″)==“-1″?false:true;
}
function isNN(){
return navigator.userAgent.indexOf(“Netscape”)!=-1;
}
function isOpera(){
return navigator.appName.indexOf(“Opera”)!=-1;
}
function isFF(){
return navigator.userAgent.indexOf(“Firefox”)!=-1;
}
function isChrome(){
return navigator.userAgent.indexOf(“Chrome”) > -1;
}
</script>
下面介紹下 js擷取用戶端瀏覽器資訊
Navigator 對象包含有關瀏覽器的資訊。js就是通過Navigator的屬性擷取用戶端瀏覽器資訊
Navigator 對象屬性:
屬性
描述
appCodeName 返回瀏覽器的代碼名。
appMinorVersion 返回瀏覽器的次級版本。
appName 返回瀏覽器的名稱。
appVersion 返回瀏覽器的平台和版本資訊。
browserLanguage 返回當前瀏覽器的語言。
cookieEnabled 返回指明瀏覽器中是否啟用 cookie 的布爾值。
cpuClass 返回瀏覽器系統的 CPU 等級。
onLine 返回指明系統是否處於離線模式的布爾值。
platform 返回運行瀏覽器的作業系統平台。
systemLanguage 返回 OS 使用的預設語言。
userAgent 返......餘下全文>>
指令碼判斷瀏覽器類型
<html>
<body>
<script type="text/javascript">
if(navigator.userAgent.indexOf("360SE")>0){
document.write("360瀏覽器");
}
else if(navigator.userAgent.indexOf("TheWorld ")>0){
document.write("世界之窗瀏覽器");
}
else if(navigator.userAgent.indexOf("Firefox")>0){
document.write("Firefox瀏覽器");
}
else if(navigator.userAgent.indexOf("Chrome")>0){
document.write("Google瀏覽器");
}
else
document.write("其他瀏覽器");
</script>
</body>
</html>