【问题标题】:How to detect if iframe open and jump to ios native app sucessfully or not如何检测iframe是否打开并成功跳转到ios原生应用程序
【发布时间】:2015-06-23 17:29:10
【问题描述】:

当用户在移动浏览器上打开我们的网站时,我使用 iframe 自动跳转到 iOS 原生应用。它工作正常。如果未安装应用程序,则它只会停留在浏览器上。

<iframe id="my-iframe" class="hidden" src="app:///" ></iframe>

现在我有一个关于跟踪应用程序是否成功打开的问题。

我尝试了一种方法:等待4s,然后检查iframe的就绪状态。但是,似乎即使app没有打开,状态仍然是“准备好”。 我在这里询问是否有任何好的方法可以成功检测 iframe 打开本机应用程序。

setTimeout(function () {
            var ifr=document.getElementById("my-iframe");
            if (ifr.contentWindow.document.readyState == 'complete' || ifr.contentWindow.document.readyState == 'interactive') {
                console.log('iframe load success');
            } else {
                console.log('iframe load failed');
            }
        }, 4000);

【问题讨论】:

    标签: javascript jquery html ios iframe


    【解决方案1】:

    试试这个:

    var ifr=document.getElementById("my-iframe");
    
    ifr.onload = function(){
        console.log('iframe load success');
    }
    

    【讨论】:

    • 不,onload 处理程序永远不会被调用,即使 iframe "src" 已加载(本机应用程序已打开)。
    • 抱歉,我想更正我之前的评论。 onload 函数会被执行。但是,无论是否打开本机应用程序(未安装),它都会执行。所以这个函数不能提供好的信息。
    猜你喜欢
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 2012-07-19
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 2019-12-14
    • 1970-01-01
    相关资源
    最近更新 更多