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);
}
}
网友评论