h5判断是否安装了某个app

2021-08-27  本文已影响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);
    }
}
上一篇 下一篇

猜你喜欢

热点阅读