+
95
-

回答

还有个方法可以检测,原理就是:启动app需要的时间较长,js中断时间长,如果没安装,js瞬间就执行完毕。直接上代码吧!

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" />
<script type="text/javascript">



function testApp(url) {
var timeout,
t = 1000,
hasApp = true;
setTimeout(function () {
if (hasApp) {
alert('安装了app');
} else {
alert('未安装app');
}
document.body.removeChild(ifr);
},
2000)

var t1 = Date.now();
var ifr = document.createElement("iframe");
ifr.setAttribute('src',
url);
ifr.setAttribute('style',
'display:none');
document.body.appendChild(ifr);
timeout = setTimeout(function () {
var t2 = Date.now();
if (!t1 || t2 - t1 < t + 100) {
hasApp = false;
}
},
t);
}
</script>
<style>
</style>
</head>
<body>
<a href="BfwJavascripttestApp('tel:18888888888')">打电话</a>
</body>
</html>


网友回复

我知道答案,我要回答