可以从页面挑战到APP,也可以从APP跳回页面啦
从网页上是没办法检测手机是否安装了某个应用,但是有一个小技巧:如果能打开本地应用的话,就会跳出页面打开(从而关掉定时器),不会转向下载页,而不能打开本地应用,就会转向下载页面
知乎代码:
$("#js-open-in-app").on("click", function() {
var b = $('meta[name="apple-itunes-app"]').attr("content");
if (b) {
b = (new jj(b.replace(/,s*/, "&"))).get("app-argument") || "";
-1 === b.indexOf("zhihu://") && (b = "zhihu://" + b);
if (/Android/.test(navigator.userAgent)) {
var c = b.replace(/^zhihu/, "intent") + "/#Intent;scheme=zhihu;package=com.zhihu.android;end", d = navigator.userAgent.match(/Chrome/(d+)/);
if (25 <= (d && d[1]))
window.location = c;
else {
c = document.createElement("iframe");
c.hidden = j;
c.src = b;
document.body.appendChild(c);
var e = za();
window.setTimeout(function() {
600 > za() - e && (window.location = "http://api.zhihu.com/client/download/apk")
}, 400)
}
} else {
var g = m;
window.location = b;
window.setTimeout(function() {
g = j;
window.location = "http://itunes.apple.com/cn/app/id432274380"
}, 250);
window.setTimeout(function() {
g && window.location.reload()
}, 500)
}
W("app-promotion", "click_zhihu_ios_open_dl_link", "header_not_logged_in")
}
})
插件