最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to browser deeplink to an app? (without popup) - Stack Overflow

programmeradmin2浏览0评论

I'm trying to deeplink into an app from the browser, that's working fine. But the problem is, that iOS is showing a "Safari can't open the page" and then redirects to the app store (fallback solution).

Is it possible to make some JS magic, so that popup box doesn't appear?

Here is the code:

    var now = new Date().valueOf();
    setTimeout(function () {
        if (new Date().valueOf() - now > 100) return;
        window.location = "";
    }, 10);
    window.location = "twitter://timeline";

I'm trying to deeplink into an app from the browser, that's working fine. But the problem is, that iOS is showing a "Safari can't open the page" and then redirects to the app store (fallback solution).

Is it possible to make some JS magic, so that popup box doesn't appear?

Here is the code:

    var now = new Date().valueOf();
    setTimeout(function () {
        if (new Date().valueOf() - now > 100) return;
        window.location = "https://itunes.apple./us/app/twitter/id333903271?mt=8";
    }, 10);
    window.location = "twitter://timeline";
Share Improve this question edited Jul 22, 2015 at 20:25 Sushanth -- 55.8k9 gold badges69 silver badges107 bronze badges asked Jul 22, 2015 at 20:15 Simon ThomsenSimon Thomsen 1,4217 gold badges28 silver badges37 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

I encountered a similar scenario some time back and I figured the best way to go about is have an iframe and provide a source to it..

function mobileDeepLink() {
    var iframe = document.createElement('iframe');
    iframe.src = "twitter://timeline";

    // hide iframe visually
    iframe.width = 0;
    iframe.height = 0;
    iframe.frameBorder = 0;

    var now = new Date().valueOf();
    setTimeout(function () {
        if (new Date().valueOf() - now > 100) return;
        window.location = "https://itunes.apple./us/app/twitter/id333903271?mt=8";
    }, 10);

    // Append it to the body.
    document.body.appendChild(iframe);
    iframe.parentNode.removeChild(iframe);
}

mobileDeepLink();

That way you would not see the error popup when the scheme cannot be found.

Update

This approach will only work for IOS 8 and lower. From IOS 9 and later, deep linking is being supported natively using universal links.

发布评论

评论列表(0)

  1. 暂无评论