gpt4 book ai didi

IOSSafari 中的 Javascript 后台进程

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:07 24 4
gpt4 key购买 nike

如果用户在他们的设备中安装了应用程序,我会尝试将他们重定向到应用程序,否则将他们重定向到应用程序下载页面 (iTunes)。我想捕获客户端最后到达的确切 url(应用程序 url 或 web url)。

是否有任何后台进程来捕获客户端提供的网址?

if (IOSSafari) 
{
window.location.href = appUrl;
var startTime = new Date();
setTimeout(function()
{
if (new Date() - startTime < 600)
{
if (window.location.href != webUrl)
window.location.href = webUrl;
}
}, 500);
}

我的尝试(我试过如下):-

if (IOSSafari) 
{
callback(appUrl); // first callback to my server to identify the user presence
window.location.href = appUrl;
var startTime = new Date();
setTimeout(function()
{
if (new Date() - startTime < 600)
{
if (window.location.href != webUrl)
{
// second callback to my server to identify the user presence
callback(appUrl);
window.location.href = webUrl;
}
}
}, 500);
}

案例 1 应用程序已安装:-

  1. 用户A进入
  2. 我的第一个回调有效,用户被重定向到应用
  3. 现在表中只有用户 A 的 appUrl 条目。这按预期工作,因为用户出现在 app(appUrl) 中。

案例2 App未安装:-

  1. 用户A进入
  2. 我的第一个回调有效,用户被重定向到应用
  3. 由于应用程序未出现在设备中,它说 safari 无法打开此页面
  4. 第二次回调有效,用户重定向到应用下载页面
  5. 现在表格有 2 个条目(带有 appUrl 的条目和带有 webUrl 的条目)用于用户 A 而不是单个条目(带有 webUrl 的条目,因为用户出现在下载页面中)

最佳答案

捕获该值的一种最简单的方法是使用客户端 cookie。

document.cookie="lasturl="+xyz+";path=/";
//xyz is webUrl or appUrl , so write the above line before calling window.location.href=...

document.cookie="lasturl="+deeplinkUrl+";path=/";
window.location.href=deeplinkUrl;

//or

document.cookie="lasturl="+webUrl+";path=/";
window.location.href=webUrl;

稍后您可以检查“lasturl”的 cookie 值

关于IOSSafari 中的 Javascript 后台进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21405091/

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