<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>判断是否为移动端</title>
</head>
<body>
</body>
<script>
function isPhone(){
var isPhone=false;
var arr=["iOS","Android","iPhone","iPad","iPod"];
for(var i=0;i<arr.length;i++){
if(navigator.userAgent.indexOf(arr[i])!=-1){
isPhone=true;
break;
}
}
return isPhone;
}
if(isPhone()){
alert('移动端');
}else{
alert('PC端');
}
</script>
</html>
使用javascript浏览器对象模型(BOM)检测打开网页的设备是否是移动端
最新推荐文章于 2022-10-17 21:11:22 发布