<!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>