美文网首页
IOS和安卓共用一个二维码实现跳转

IOS和安卓共用一个二维码实现跳转

作者: xilong | 来源:发表于2018-10-16 17:57 被阅读50次

    1、芝麻二维码生成器

    可以把 iOS下载地址 和 安卓下载地址生成一个二维码(我觉得原理应该是跳转到一个中转地址)

    2、跳转到一个中转地址

    当用户扫描二维码之后,手机会跳转到一个中转地址,这个是一个空白页面,里面判断手机系统然后下载相应资源。
    所以这个二维码就是这个中转地址生成的。

    代码

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    
        <script>
    
        /**
            出来的链接大概是长这样的
            http://xxx.cn/1234.html?c=Q23AD12
        */
    
        // c=Q23DR32是注册时扫描获取的邀请码。
        // 这样加参数,后面的参数会被自动忽略,不会影响加载此网页
    
            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 = 'http://xxxxxxx.cn/release/xxxx-release.apk'; // 跳安卓端下载地址
                }
                // 这里是iOS浏览器
                if (isIOS) {
                    window.location.href = 'https://itunes.apple.com/cn/app/xxxxxxx/id1124348115?mt=8'; // 跳AppStore下载地址
                }
    
                // 是微信内部webView
                if (is_weixn()) {
                    alert("请点击右上角按钮, 点击使用浏览器打开");
                }
    
                // 是PC端
                if (IsPC()) {
                    window.location.href = 'http://www.xxxxxxx.cn/index.html';  // 公司主页
                }
            }
    
            // 是微信浏览器
            function is_weixn(){
                var ua = navigator.userAgent.toLowerCase();
                if(ua.match(/MicroMessenger/i)=="micromessenger") {
                    return true;
                } else {
                    return false;
                }
            }
    
    
            function IsPC() {
                var userAgentInfo = navigator.userAgent;
                var Agents = ["Android", "iPhone",
                    "SymbianOS", "Windows Phone",
                    "iPad", "iPod"];
                var flag = true;
                for (var v = 0; v < Agents.length; v++) {
                    if (userAgentInfo.indexOf(Agents[v]) > 0) {
                        flag = false;
                        break;
                    }
                }
                return flag;
            }
    
        </script>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:IOS和安卓共用一个二维码实现跳转

          本文链接:https://www.haomeiwen.com/subject/mtnhzftx.html