// 判断手机上是否存在某App 如果存在就拉起App 否则 跳转至下载链接
// (agreement)为App给web的一个协议,为APP那边提供
//原理:按拉起时间判断,手机上是否存在该APP
function testApp(agreement,url) {
var t = 1000, hasApp = true;
setTimeout(function () {
if (hasApp) {
return false;
} else {
window.location.href = url; //如果手机上不存在该应用,则跳转至该链接。
}
document.body.removeChild(ifr);
}, 2000);
var t1 = Date.now();
var ifr = document.createElement("iframe");
ifr.setAttribute('src', agreement);
ifr.setAttribute('style', 'display:none');
document.body.appendChild(ifr);
setTimeout(function () {
var t2 = Date.now();
if (!t1 || t2 - t1 < t + 100) {
hasApp = false;
}
}, t);
};
发布评论