首页 > 代码库 > js判断设备是iOS还是安卓

js判断设备是iOS还是安卓

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />

<title></title>

<style>div{width: 200px;height: 200px;background: #f06;}</style>

</head>

<body>

<div id="download">点击判断设备是iOS还是安卓</div>

<script src="http://www.mamicode.com/js/jquery.js"></script>

<script>

var download = {

downloadApp : function(){

var xt = navigator.userAgent;

if(xt.indexOf("iPhone") > -1){

window.location.href="http://www.baidu.com";

}else{

window.location.href="http://3g.163.com/touch/all?dataversion=A&version=v_standard";

}

}

};

$(function(){

$("#download").click(function(){

download.downloadApp();

});

})

</script>

</body>

</html>

 

js判断设备是iOS还是安卓