用js如何判断打开网页的是安卓还是ios?
我要做个html页面,有个链接下载app,如果是苹果手机打开就下载ios版安卓就下载安卓版,
如何用js区分?
<script type = "text/javascript">
$(function(){
var ua = navigator.userAgent.toLowerCase();
if (/iphone|ipad|ipod/.test(ua)) {
$("a").attr("href","https://itunes.apple.com/us/app/ren-ren-duo-bao-yi-ge-shou/id1111430715?l=zh&ls=1&mt=8");
} else {
$("a").attr("href","http://www.rrdb8.com/statics/templates/app/RenRenDuoBao.apk");
}
})
</script>
做出来了
呃,我之前判断过android和iPhone,直接判断UA,如果是iOS的话,参考其他人的答案