日常小记

JS识别判断Android/IOS设备实现跳转不同的下载地址

<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,user-scalable=no">
    <title>JS识别判断Android/IOS设备实现跳转不同的下载地址</title>
    <style type="text/css">
        a{ text-decoration: none;}
        img{ display: block; margin: 0 auto; width: 100%; border: 0;}
        .btn{ width: 100%; position: fixed; bottom: 0; min-width: 320px;  background: #fefefe;  padding: 12px 0;
              color: #fff; text-align: center; line-height: 45px; border-radius: 3px; border-top: 1px solid #dcdcdc;
        }
        .btn a{ height: 45px; background:#25cffb ; color: #fff; display: block; width: 90%; margin: 0 auto; font-size: 18px; font-weight: bold;}
    </style>
</head>
<body>
    <a href="javascript:void(0)" onclick="jump()">
        <!-- 软件截图/海报地址 -->
        <img src="./123.png" />
    </a>
    <div class="btn">
        <a href="javascript:void(0)" onclick="jump()">
            立即下载
        </a>
    </div>
    <script src="jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
    function jump(){
        var u = navigator.userAgent, app = navigator.appVersion;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if(isAndroid==1){
            // 替换安卓下载地址
            window.location.href="http://www.baidu.com"
        }
        else(
            // 替换苹果ios的下载地址
            window.location.href="http://www.google.com"
        )
    }

// alert('是否是Android:'+isAndroid);
// alert('是否是iOS:'+isiOS);

    </script>
</body>

</html>

回复

This is just a placeholder img.