判斷瀏覽器類型,判斷瀏覽器

來源:互聯網
上載者:User

判斷瀏覽器類型,判斷瀏覽器

做前端時,需判斷使用者瀏覽器類型:

一段小小代碼

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>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.