app下载

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_38747509/article/details/85060058
// //app下载
    toDownload() {
        if (app.isInApp()) {
            // window.location.href = "mceair://perfect.ceair/deeplink?typeKey=mainview";
        } else {
            //h5
            if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
                window.location = "https://itunes.apple.com/cn/app/dong-fang-hang-kong-dong-hang/id419275564?mt=8";
            } else if (navigator.userAgent.match(/android/i)) {
                //在iframe 中打开APP
                var ifr = document.createElement('iframe');
                ifr.src = "mceair://perfect.ceair/deeplink?typeKey=mainview";
                ifr.style.display = 'none';
                //客户端检测微信直接跳应用宝链接
                if (Boolean(navigator.userAgent.match(/MicroMessenger/ig))) {
                    window.location.href = 'https://sj.qq.com/myapp/detail.htm?apkName=com.rytong.ceair&android_schema=com.rytong.ceair';
                } else {
                    this.checkOpen(opened => {
                        // console.log(opened)
                        if (opened == 1) {
                            window.location = "http://mobile.ceair.com/dl.html"
                        }
                    }
                    );
                }
                document.body.appendChild(ifr);
                setTimeout(function () {
                    document.body.removeChild(ifr);
                }, 3000);
                // window.location = "https://mobile.ceair.com/";
            }
        }
    },
    checkOpen(cb) {
        var _clickTime = +(new Date());
        function check(elsTime) {
            if (elsTime > 3000 || document.hidden || document.webkitHidden) {
                cb(1);
            } else {
                cb(0);
            }
        }
        //启动间隔20ms运行的定时器,并检测累计消耗时间是否超过3000ms,超过则结束
        var _count = 0, intHandle;
        intHandle = setInterval(function () {
            _count++;
            var elsTime = +(new Date()) - _clickTime;
            if (_count >= 100 || elsTime > 3000) {
                clearInterval(intHandle);
                check(elsTime);
            }
        }, 100);
    }

猜你喜欢

转载自blog.csdn.net/weixin_38747509/article/details/85060058