史上最简单,js并获取手机型号
原先获取不了苹果系列的型号,但转换思路,先推断是否是苹果,再用分辨率获取型号
//获取手机型号函数begin
function getPhoneType(){
//正则,忽略大写和小写
var pattern_phone = new RegExp("iphone","i");
var pattern_android = new RegExp("android","i");
var userAgent = navigator.userAgent.toLowerCase();
var isAndroid = pattern_android.test(userAgent);
var isIphone = pattern_phone.test(userAgent);
var phoneType="phoneType";
if(isAndroid){
var zh_cnIndex = userAgent.indexOf("-");
var spaceIndex = userAgent.indexOf("build",zh_cnIndex+4);
var fullResult = userAgent.substring(zh_cnIndex,spaceIndex);
phoneType=fullResult.split(";")[1];
}else if(isIphone){
//6 w=375 6plus w=414 5s w=320 5 w=320
var wigth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
if(wigth>400){
phoneType = "iphone6 plus";
}else if(wigth>370){
phoneType = "iphone6";
}else if(wigth>315){
phoneType = "iphone5 or iphone5s";
}else{
phoneType = "iphone 4s";
}
}else{
phoneType = "您的设备太先进了";
}
return phoneType;
}
//end
//手机touch事件開始
<script>
function load (){
document.addEventListener('touchstart',touch, false);
document.addEventListener('touchmove',touch, false);
document.addEventListener('touchend',touch, false);
function touch (event){
var event = event || window.event;
var oInp = document.getElementById("inp");
switch(event.type){
case "touchstart":
oInp.innerHTML = "Touch started (" + event.touches[0].clientX + "," + event.touches[0].clientY + ")";
break;
case "touchend":
oInp.innerHTML = "<br>Touch end (" + event.changedTouches[0].clientX + "," + event.changedTouches[0].clientY + ")";
break;
case "touchmove":
event.preventDefault();
oInp.innerHTML = "<br>Touch moved (" + event.touches[0].clientX + "," + event.touches[0].clientY + ")";
break;
}
}
}
window.addEventListener('load',load, false);
</script>
//touch事件结束
史上最简单,js并获取手机型号的更多相关文章
- 史上最简单JS复制功能,兼容安卓ios!
1.JS复制原理: 被复制内容的元素不能被其他元素遮盖,否则无效. (设置opacity透明为0,不可以设置display:none); 2.常规的复制方法 function copyUrl2() ...
- 史上最简单的 SpringCloud 教程 | 终章
https://blog.csdn.net/forezp/article/details/70148833转载请标明出处:http://blog.csdn.net/forezp/article/det ...
- JS获取手机型号和系统
废话不多说,直接上源码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&q ...
- 史上最全的 jmeter 获取 jdbc 数据使用的4种方法——(软件测试Python自动化)
周五,下班了吗?软件测试人. 明天是周末了!给大家推荐一个技术干货好文.史上最全的 jmeter 获取 jdbc 数据使用的四种方法.我也精剪了jmeter的自动化接口测试的视频放在了同名UP主,周末 ...
- 史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS。
重要的话 开头说,not for the RecyclerView or ListView, for the Any ViewGroup. 本控件不依赖任何父布局,不是针对 RecyclerView. ...
- [分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例)
[分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例) 踏雁寻花 发表于 2015-8-23 23:31:28 https://www.itsk.com/thread-35 ...
- 史上最简单的 SpringCloud 教程
史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)史上最简单的SpringCloud教程 | 第二篇: 服务消费者(rest+ribbon)史上最简单的Spri ...
- 史上最简单的 GitHub 教程
史上最简单的 GitHub 教程 温馨提示:本系列博文已经同步到 GitHub,如有需要的话,欢迎大家到「github-tutorial」进行Star和Fork操作! 1 简介 GitHub 是一个面 ...
- (转) 史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)
一.spring cloud简介 spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选.分布式会话等等.它运 ...
随机推荐
- Markdown编辑器 常用语法
一.标题 示例: # 1这是一级标题 ## 2这是二级标题 ### 3这是三级标题 #### 4这是四级标题 ##### 5这是五级标题 ###### 6这是六级标题 效果如下: 1这是一级标题 2这 ...
- iPad popView封装
仿照UITableView的UITableViewDataSource 协义 1.代理.让代理帮我们类完毕一些方法 2.完毕当前类不能完毕的事情还有传值等功能 实现方法 // 1. 声明一个协议 // ...
- Android GridView LruCache
照片墙这种功能现在应该算是挺常见了,在很多应用中你都可以经常看到照片墙的身影.它的设计思路其实也非常简单,用一个GridView控件当作“墙”,然后随着GridView的滚动将一张张照片贴在“墙”上, ...
- ADO.Net数据库帮助类
public interface IDBHelper { /// <summary> /// 执行sql语句 /// </summary> /// <param name ...
- HDU 5353 Average 贪心
就是贪心啊,不知道为啥总是不过,总是WA 方法不对吗? 将数组扩展一倍,从左到右扫描,大于平均数就给右边的,小于就从右边拿,等于就不变,记录下操作类型. 大于2直接NO,不知道哪错了,自己出了一些数据 ...
- RedHat Linux 多媒体学习指南 (共 36 部原创视频)
1.为sco unix 添加第二块网卡 [url]http://you.video.sina.com.cn/b/11695632-1443650204.html[/url] 2.为sco unix ...
- C/C++(C++返回对象与应用区别,类成员的存储)
返回对象与应用区别: 拷贝构造器发生的时机: 1.构造新对象 A a, A b = a; 2.传参或返回对象 对于普通变量来说,传引用效果不是很明显,对于类对象而言,传对象效果很高. 传引用等价于扩大 ...
- 把书《CUDA By Example an Introduction to General Purpose GPU Programming》读薄
鉴于自己的毕设需要使用GPU CUDA这项技术,想找一本入门的教材,选择了Jason Sanders等所著的书<CUDA By Example an Introduction to Genera ...
- Safe and efficient allocation of memory
Aspects of the present invention are directed at centrally managing the allocation of memory to exec ...
- 安卓https
http://www.tuicool.com/articles/NrmE3e http://blog.csdn.net/guestcode/article/details/50194357 http: ...