PhoneGap中文网

 找回密码
 立即注册
查看: 21302|回复: 6
打印 上一主题 下一主题

js判断手机是android 还是ios 还是BlackBerry

[复制链接]

493

主题

2035

帖子

6894

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
6894
跳转到指定楼层
楼主
发表于 2014-11-17 23:10:48 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式


我们有时候为了做一些手机浏览器的兼容,可能会在手机上用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)


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

ionic4视频教程

Archiver|手机版|小黑屋| PhoneGap中文网 ( 京ICP备13027796号-1 )  

GMT+8, 2024-5-5 12:10 , Processed in 0.044039 second(s), 33 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表