gpt4 book ai didi

php - 在 PHP 中深度链接应用程序不起作用

转载 作者:行者123 更新时间:2023-12-01 16:33:53 25 4
gpt4 key购买 nike

我有一个网页需要检查是否存在使用深层链接的应用程序,但它似乎无法正常工作。我尝试了以下事情。

  • 在 PHP 中使用重定向(不起作用)
  • header('Location: exampleapp://param=test');
  • 使用 JavaScript 使用重定向(不起作用)
    var appurl = 'exampleapp://param=test';
    var appstore = 'https://itunes.apple.com/us/app/...';

    var timeout;
    function preventPopup() {
    clearTimeout(timeout);
    timeout = null;
    window.removeEventListener('pagehide', preventPopup);
    }
    function startApp() {
    window.location = appurl;
    timeout = setTimeout(function(){
    if(confirm('You do not seem to have the App installed, do you want to go download it now?')){
    document.location = appstore;
    }
    }, 100);
    window.addEventListener('pagehide', preventPopup);
    }

    // app start is then called in the onload
  • 与上面相同,但替换行 window.location = appurl;document.getElementById('deeplink').click();并在 html 的网页中添加一个链接。 (作品)<a id="deeplink" href="exampleapp://param=test">Deep Link</a>

  • 为什么不能在 PHP 中使用 header 重定向是有原因的吗?

    最佳答案

    由于 HTTP 的工作方式,PHP 版本不起作用。 HTTP 协议(protocol)没有指定它应该能够从“Location:” header 中重定向到不同的协议(protocol)。这里没有什么特定于 PHP 的,这是一个 HTTP 问题。

    Javascript 版本不起作用,因为您想设置窗口位置。并且窗口不能显示 "exampleapp://..."的内容。您希望链接在用户单击它时打开。而不是使用 window.location您可以使用 document.location.href .那应该行得通。

    另一个问题:
    在你写的代码中exampleapp://在 1) 和 2) 中。在 3) 中你写 testapp:// - 确保您在所有三种情况下都使用相同的 URL,这样您就可以确保该 URL 最终可以正常工作。

    关于php - 在 PHP 中深度链接应用程序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29929263/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com