使用navigator.userAgent.toLowerCase()判斷移動端類型

來源:互聯網
上載者:User

標籤:csdn   判斷   tor   logs   lower   sse   版本   substring   ==   

使用navigator.userAgent.toLowerCase()判斷移動端類型

判斷裝置,區分Android,iphone,ipad和其它

var ua   = navigator.userAgent.toLowerCase();   if(ua.match(/android/i)) == "android")  {      alert("android");  }  if(ua.match(/iPhone/i)) == "iPhone")  {      alert("iPhone");  }  if(ua.match(/iPad/i)) == "iPad")  {      alert("iPad");  }  

判斷是不是特定類型的瀏覽器,比如新浪weibo用戶端內建瀏覽器,qq用戶端內建瀏覽器(而非qq瀏覽器),內建瀏覽器

(並且區分版本是否大於等於6.0.2)(特定類型瀏覽器可能會存在,無法下載,無法跳轉和自己的用戶端app的特定協議等等,所以需要區分)

(由於在6.0.2的時候做了新的策略,使得的分享功能在新版本變得不一樣,為了相容新舊版本,這裡做了區分操作)

新浪weibo用戶端返回1,qq用戶端返回2,小於6.0.2版本返回3,大於等於6.0.2版本返回4,其它返回0

var ua = navigator.userAgent.toLowerCase();      if(ua.match(/weibo/i) == "weibo"){          return 1;      }else if(ua.indexOf(‘qq/‘)!= -1){          return 2;      }else if(ua.match(/MicroMessenger/i)=="micromessenger"){          var v_weixin = ua.split(‘micromessenger‘)[1];          v_weixin = v_weixin.substring(1,6);          v_weixin = v_weixin.split(‘ ‘)[0];          if(v_weixin.split(‘.‘).length == 2){              v_weixin = v_weixin + ‘.0‘;          }          if(v_weixin < ‘6.0.2‘){              return 3;          }else{              return 4;          }      }else{          return 0;      }  

  

使用navigator.userAgent.toLowerCase()判斷移動端類型

聯繫我們

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