PhoneGap中文网

标题: js判断手机是android 还是ios 还是BlackBerry [打印本页]

作者: admin    时间: 2014-11-17 23:10
标题: js判断手机是android 还是ios 还是BlackBerry


我们有时候为了做一些手机浏览器的兼容,可能会在手机上用js判断 手机是android 还是ios 还是BlackBerry 还是windows phone

下面的js代码大家可以试试,最下面也有zip包下载地址,到时候上传到网站,然后在手机浏览器打开 测试一下就知道了



  1. var isMobile = {
  2.             Android: function() {
  3.                 return navigator.userAgent.match(/Android/i);
  4.             },
  5.             BlackBerry: function() {
  6.                 return navigator.userAgent.match(/BlackBerry/i);
  7.             },
  8.             iOS: function() {
  9.                 return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  10.             },
  11.             Opera: function() {
  12.                 return navigator.userAgent.match(/Opera Mini/i);
  13.             },
  14.             Windows: function() {
  15.                 return navigator.userAgent.match(/IEMobile/i);
  16.             },
  17.             any: function() {
  18.                 return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
  19.             }
  20.         };
  21.        
  22.         if ( isMobile.Android() ) {
  23.                
  24.                 alert('android');
  25.             //document.location.href = "y";
  26.         }
  27.         else if(isMobile.iOS())
  28.         {               
  29.                 alert('IOS');
  30.             //document.location.href="x";
  31.         }       
复制代码


js判断手机版本.zip (476 Bytes, 下载次数: 26)



作者: wctdan26    时间: 2015-3-27 23:44
谢谢分享
作者: dyh    时间: 2015-4-30 15:51
未来属于html5 phonegap 微信 wap全部搞定
作者: caishaolin    时间: 2015-4-30 20:40
html5 是趋势
作者: citydream    时间: 2015-4-30 22:31
好帖就是要顶 学习学习 html5趋势不可挡啊,虽然还在学习阶段
作者: madduck    时间: 2015-5-1 04:24
人不错,学习学习 感觉phonegap+html越来越火了。
作者: caishaolin    时间: 2015-5-1 16:44
非常好 感谢 开始学习html5 app开发了




欢迎光临 PhoneGap中文网 (http://bbs.phonegap100.com/) Powered by Discuz! X3.2