h5页面判断移动端系统为Android或IOS
2024-08-24 23:15:50
最近遇到了一个需求,即所谓的 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系统的移动端页面做点什么 }
最新文章
- mvc上传到云虚拟机的问题解决
- Spring注解@PostConstruct与@PreDestroy
- Jmeter—4 添加断言 判断响应数据是否符合预期
- python如何安装pip和easy_installer工具
- Introducing shard translator
- 3. 戏说VHDL之入门游戏一:流水灯
- OpenCASCADE 基础
- ES6笔记① var 和 let的区别
- 12.04 ubuntu 更改IP
- ExpandableListView使用
- (六十二)纯代码搭建UI
- 全网搜歌神器Listen1 Mac中文版
- 如何让ajax执行完后再继续往下执行
- (转)获取 request 中用POST方式";Content-type";是";application/x-www-form-urlencoded;charset=utf-8";发送的 json 数据
- jQuery获取子元素的个数
- 多张图片合成一个tif
- 《快学Scala》第五章 类
- 利用json模块解析dict报错找不到attribute 'dumps'[python2.7]
- Codeforces Round #302 (Div. 1) B - Destroying Roads
- OpenCV使用标定图