使用iPhone上的Safari确定已安装的应用程序 [英] Determine an installed app using Safari on iPhone

查看:101
本文介绍了使用iPhone上的Safari确定已安装的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iPhone Safari上使用自定义网址方案确定已安装的应用。

I would like to determine an installed app using custom URL scheme on iPhone Safari.

您可能认为这样做是不可能的,但JavaScript帮我算一下这个。

You may believe it is impossible to do this, but JavaScript helped me to figure this out.

  <script>(function(){

var fallbackLink = '<?=$info['failed_url']?>'+window.location.search+window.location.hash;

var isiOS = navigator.userAgent.match('iPad') || navigator.userAgent.match('iPhone'),
    isAndroid = navigator.userAgent.match('Android');

if (isiOS || isAndroid) {
  document.getElementById('loader').src = '<?=$info['scheme']?>://'+window.location.search+window.location.hash;

  fallbackLink = isAndroid ? '<?=$info['failed_url']?>' :
                             '<?=$info['failed_url']?>' ;
}
window.setTimeout(function (){ window.location.replace(fallbackLink); }, 1000);

})();</script>

这是我的剧本。

I已经知道iPhone应用程序的自定义URL方案。如果应用程序存在于iPhone上,它会成功启动它。但是,如果iPhone没有应用程序,它会重定向到不同的页面。

I already know custom URL scheme of the iPhone application. It successfully launches the application if it exists on the iPhone. However, if the iPhone doesn't have the application, it redirects to a different page.

我在失败的网页上放置了某些代码,注意到用户没有有应用程序。我的计划是完美的,直到我找到了。

I put certain code on the failed web page to notice that user doesn't have the application. My plan was perfect until I found this.

即使应用程序在超时后在iPhone上启动,JavaScript重定向仍然有效。

如果iPhone启动应用程序,有没有办法停止JavaScript?

Is there a way to stop JavaScript if iPhone launched application?

谢谢。

推荐答案

当窗口失去焦点时,你总是可以取消超时。

You can always cancel the timeout when the window loses focus.

var countdown = window.setTimeout(function (){
    window.location.replace(fallbackLink);
}, 1000);

window.addEventListener("blur", function (){
    window.clearTimeout(countdown);
}, false);

这篇关于使用iPhone上的Safari确定已安装的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆