可以!
1、使用mobile-detect.js
2、html
<!DOCTYPEhtml>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/htmlcharset=UTF-8"/>
<metaname="viewport"
content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>JS获取手机型号和系统</title>
</head>
<body>
</body>
<script src="jquery.js"></script>
<script src="mobile-adapt.js"></script>
<script>
//判断数组中是否包含某字符串
Array.prototype.contains=function(needle){
for(iinthis){
if(this[i].indexOf(needle)>0)
returni
}
return-1
}
vardevice_type=navigator.userAgent//获取userAgent信息
document.write(device_type)//打印到页面
varmd=newMobileDetect(device_type)//初始化mobile-detect
varos=md.os()//获取系统
varmodel=""
if(os=="iOS"){//ios系统的处理
os=md.os()+md.version("iPhone")
model=md.mobile()
}elseif(os=="AndroidOS"){//Android系统的处理
os=md.os()+md.version("Android")
varsss=device_type.split("")
vari=sss.contains("Build/")
if(i>-1){
model=sss[i].substring(0,sss[i].indexOf("Build/"))
}
//判断是否是oppoR9s
if(model="OPPOR9s"){
alert('您的手机是OPPOR9s')
}
if(model=="MI6"){
alert('您的手机是小米6')
}
}
alert('111'+model+'2222')//打印系统版本和手机型号
</script>
</html>
在H5页面的开发中,肯定会遇到获取手机的型号等需求,使用js的navigator对象,能获取到有关浏览器的相关信息,但想获取手机使用的系统等更多内容还是有局限性的。
在网上搜到一个好用的获取手机型号和系统的插件 mobile-detect.js
2.引用mobile-detect.js
实例化一个MobileDetect
在浏览器中使用三星模拟器测试可以打印安卓型号 5.0:
使用iphone打印iphone型号ios11:
这个还是不能准确定位使用的是什么型号的手机,但可以通过返回的信息判断使用的是安卓还是苹果的,比如苹果结合获取设备屏幕大小和io系统的型号就可以判断出使用的是什么iphone手机,至于安卓手机类型比较多,就要复杂很多啦,大家知道的可以相互分享啊。
<scripttype="text/javascript"><!--
function detectOS() {
isWindows = (navigator.userAgent.indexOf("Windows",0) != -1)?1:0
isMac = (navigator.userAgent.indexOf("mac",0) != -1)?1:0
isLinux = (navigator.userAgent.indexOf("Linux",0) != -1)?1:0
isUnix = (navigator.userAgent.indexOf("X11",0) != -1)?1:0
if (isWindows)
return"MS Windows"
if (isMac)
return"Apple Mac"
if (isLinux)
return"Lunix"
elseif (isUnix)
return"Unix"
return"Unknown"
}
//-->
</script>