javascript - 用JS如何判断打开网页的是安卓还是ios

查看:106
本文介绍了javascript - 用JS如何判断打开网页的是安卓还是ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

用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的话,参考其他人的答案

function getOS(){
    var ua = window.navigator.userAgent.toLowerCase(),
        iPhone = /iphone/i.test(ua) ? true : false,
        android = /android/i.test(ua) ? true : false;
    
    return {android:android, iPhone:iPhone};
}

这篇关于javascript - 用JS如何判断打开网页的是安卓还是ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆