一个二维码实现同时支持AppStore下载地址 、安卓端下载地址

来源:互联网 发布:mac cd命令进入文件夹 编辑:程序博客网 时间:2024/05/17 21:59

1.有时我们需要把 AppStore下载地址 、安卓端下载地址 同时支持两个操作系统的手机扫描,分别跳向不同的地址

思路是,让二维码的地址指向html页,然后在html页面里面进行判断。


下面是html页面


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>二维码同时支持安卓端与IOS端下载地址</title>
</head>
<body>
    <script type="text/javascript">       


        goDownload();


        // 去下载
        function goDownload() {
            var u = navigator.userAgent, app = navigator.appVersion;
            var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
            var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
            // 这里是安卓浏览器
            if (isAndroid) {
                window.location.href = 'https://www.baidu.com/'; // 跳安卓端下载地址,此处用百度地址作为测试地址
            }
            // 这里是iOS浏览器
            if (isIOS) {
                window.location.href = 'http://www.sohu.com/'; // 跳AppStore下载地址,此处用搜狐地址作为测试地址
            }


            // 是微信内部webView
            if (is_weixn()) {
                alert("请点击右上角按钮, 点击使用浏览器打开");
            }
        }


        // 是微信浏览器
        function is_weixn() {
            var ua = navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == "micromessenger") {
                return true;
            } else {
                return false;
            }
        }
        
    </script>
</body>
</html>

1 0
原创粉丝点击