Javascript判斷智能手機瀏覽器

來源:互聯網
上載者:User

  參考: http://www.cnblogs.com/phphuaibei/archive/2011/12/09/2282570.html

  

var browser = {versions : function () {var u = navigator.userAgent,app = navigator.appVersion;return {trident : u.indexOf('Trident') > -1, //IE核心presto : u.indexOf('Presto') > -1, //opera核心webKit : u.indexOf('AppleWebKit') > -1, //蘋果、Google核心gecko : u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //Firefox核心mobile : !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否為移動終端ios : !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios終端android : u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android終端或者uc瀏覽器iPhone : u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否為iPhone或者QQHD瀏覽器iPad : u.indexOf('iPad') > -1, //是否iPadwebApp : u.indexOf('Safari') == -1, //是否web應該程式,沒有頭部與底部linux : u.indexOf('linux') > -1, //加mobile和這個屬性一起,可以判斷uc瀏覽器wp7 : (u.indexOf('WP7') > -1) || (u.indexOf('Windows Phone OS') > -1) //trident IE核心 並且包含WP7標示 windows phone7手機};}(),language : (navigator.browserLanguage || navigator.language).toLowerCase()};document.write("language: " + browser.language + '</br>');document.write("android: " + (browser.versions.mobile && browser.versions.android) + '</br>');document.write("iPhone: " + (browser.versions.mobile && browser.versions.iPhone) + '</br>');document.write("iPad: " + (browser.versions.mobile && browser.versions.iPad) + '</br>');document.write("Wp7: " + (browser.versions.trident && browser.versions.wp7) + '</br>');document.write(navigator.userAgent);

 

  1. 對於第三方瀏覽器,比如百度,QQ,UC等這一類的,很多都比較奇葩。我測試了UC瀏覽器在windows phone 7上不同機型的值,UserAgent差異很大。

  2. 另一方面,windows phone 7在設定中可以設定瀏覽器的模式,存在Desktop和Mobile兩種模式,這2種模式存在不同的UserAgent,需要特別注意。

相關文章

聯繫我們

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