javascript userAgent 擷取使用者瀏覽器類型

來源:互聯網
上載者:User

網頁特效 useragent 擷取使用者瀏覽器類型

var useragent = navigator.useragent.tolowercase();

useragent屬性文法
navigator.useragent;
useragent屬性說明

屬性   描述  
appcodename   擷取瀏覽器的代碼名稱。  
appminorversion   擷取應用程式的次版本值。  
appname   擷取瀏覽器的名稱。  
appversion   擷取瀏覽器啟動並執行平台和版本。  
browserlanguage   擷取瀏覽器的當前語言。  
cookieenabled   擷取用戶端的永久   cookie   是否在瀏覽器中啟用。永久   cookies   是儲存在用戶端電腦上的。  
cpuclass   擷取指示   cpu   等級的字串。  
online   擷取表明系統是否處於全域離線模式的值。  
platform   擷取使用者的作業系統名稱。  
systemlanguage   擷取作業系統適用的預設語言。  
useragent   擷取等同於   http   使用者代理程式要求標頭的字串。  
userlanguage   擷取作業系統的自然語言設定。

通常使用navigator.useragent屬性判斷使用者使用的瀏覽器與作業系統,夢之都的作業系統使用率統計與瀏覽器使用率統計都是通過useragent屬性獲得的

var is_webtv = useragent.indexof('webtv') != -1;


indexof() 方法可返回某個指定的字串值在字串中首次出現的位置。

文法
stringobject.indexof(searchvalue,fromindex)參數 描述
searchvalue 必需。規定需檢索的字串值。
fromindex 可選的整數參數。規定在字串中開始檢索的位置。它的合法取值是 0 到 stringobject.length - 1。如省略該參數,則將從字串的首字元開始檢索。

說明
該方法將從頭到尾地檢索字串 stringobject,看它是否含有子串 searchvalue。開始檢索的位置在字串的 fromindex 處或字串的開頭(沒有指定 fromindex 時)。如果找到一個 searchvalue,則返回 searchvalue 的第一次出現的位置。stringobject 中的字元位置是從 0 開始的

 

var is_kon = useragent.indexof('konqueror') != -1;
var is_mac = useragent.indexof('mac') != -1;
var is_saf = useragent.indexof('applewebkit') != -1 || navigator.vendor == 'apple computer, inc.';
var is_opera = useragent.indexof('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'gecko' && !is_saf) && useragent.substr(useragent.indexof('firefox') + 8, 3);
var is_ns = useragent.indexof('compatible') == -1 && useragent.indexof('mozilla') != -1 && !is_opera && !is_webtv && !is_saf;
var is_ie = (useragent.indexof('msie') != -1 && !is_opera && !is_saf && !is_webtv) && useragent.substr(useragent.indexof('msie') + 5, 3);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.