美文网首页
h5判断是否安装了某个app

h5判断是否安装了某个app

作者: 换昵称了 | 来源:发表于2021-08-27 18:08 被阅读0次
    export function openApp(url) {
        let ua = navigator.userAgent.toLowerCase();
        const isAndroid = uni.getSystemInfoSync().platform === 'android';
        const isVivo= ua.match(/vivo/i) == "vivo";// vivo手机读取不到安卓属性 
        if (isAndroid || isVivo) {
            let hasApp = true, t = 1000,
                t1 = Date.now(),
                ifr = document.createElement("iframe");
            setTimeout(function () {
                if (!hasApp) {
                    window.location.href = url
                }
                document.body.removeChild(ifr);
            }, 2000);
            ifr.setAttribute('src', url);
            ifr.setAttribute('style', 'display:none');
            document.body.appendChild(ifr);
            setTimeout(function () { //启动app时间较长处理
                let t2 = Date.now();
                if (t2 - t1 < t + 100) {
                    hasApp = false;
                }
            }, t);
        }
    }
    

    相关文章

      网友评论

          本文标题:h5判断是否安装了某个app

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