最近遇到了一个需求,即所谓的 app+web 混合开发,需要将 h5 内嵌到 APP 中,这个时候因为要对 Android 和 IOS 有不同的处理逻辑,所以我们就需要判断一下,移动端的系统到时是哪一种。下面我们就提供一下判断型号的方法,代码如下:

function detect(){
let equipmentType = "";
let agent = navigator.userAgent.toLowerCase();
let android = agent.indexOf("android");
let iphone = agent.indexOf("iphone");
let ipad = agent.indexOf("ipad");
if(android != -1){
equipmentType = "android";
}
if(iphone != -1 || ipad != -1){
equipmentType = "ios";
}
return equipmentType;
}

  

  在上面的方法中,返回值为 android 则为 Android 系统,返回值为 ios 则为 IOS 系统。判断完型号,就可以执行对应操作了。

if(detect()==='android'){
//对Android系统的移动端页面做点什么 }else if(detect()==='ios'){
//对IOS系统的移动端页面做点什么 }

  

最新文章

  1. mvc上传到云虚拟机的问题解决
  2. Spring注解@PostConstruct与@PreDestroy
  3. Jmeter—4 添加断言 判断响应数据是否符合预期
  4. python如何安装pip和easy_installer工具
  5. Introducing shard translator
  6. 3. 戏说VHDL之入门游戏一:流水灯
  7. OpenCASCADE 基础
  8. ES6笔记① var 和 let的区别
  9. 12.04 ubuntu 更改IP
  10. ExpandableListView使用
  11. (六十二)纯代码搭建UI
  12. 全网搜歌神器Listen1 Mac中文版
  13. 如何让ajax执行完后再继续往下执行
  14. (转)获取 request 中用POST方式"Content-type"是"application/x-www-form-urlencoded;charset=utf-8"发送的 json 数据
  15. jQuery获取子元素的个数
  16. 多张图片合成一个tif
  17. 《快学Scala》第五章 类
  18. 利用json模块解析dict报错找不到attribute 'dumps'[python2.7]
  19. Codeforces Round #302 (Div. 1) B - Destroying Roads
  20. OpenCV使用标定图

热门文章

  1. 1.什么是springboot
  2. node 崩 处理
  3. C#中使用IndexOf()判断字符串在字符串数组中第一次出现的索引位置
  4. NPOI 导出Excel表报错
  5. MongoDB-2 安装与配置
  6. 第十八篇 Linux环境下常用软件安装和使用指南
  7. bugku 隐写2
  8. CDQ 分治
  9. Atcoder Beginner Contest153F(模拟)
  10. Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)