当用户同时离开页面时,http 请求会发生什么?

发布于 2024-08-09 00:48:04 字数 337 浏览 3 评论 0原文

我想在客户端上保留一些信息,即单击了哪个元素,从而将信息保存在 cookie 中,但它是第三方 cookie,因为我需要在另一个页面上提供此信息(附属跟踪是上下文),所以我据我所知,必须通过 http 请求设置它。 Javascript 只允许我在同一个域中放置 a - 单击后将保留该域。

现在我可以通过 Javascript 使用 onbeforeunload 事件发送 http 请求,但是一旦浏览器离开页面,这个 http 请求会发生什么?它是否仍然“接听电话”并放置 cookie,或者由于发出请求的网站已不存在而忽略该电话?

找不到这方面的任何文档,所以如果有人有线索,我将不胜感激。

谢谢, 本杰明

I'd like to keep some information on the client which element was clicked and thus save the information within a cookie, but it's a third party cookie because I need this information on antoher page (affiliate-tracking is the context) so I'd have to set it via http request as far as I see it. Javascript would only allow me to place a within the same domain - which will be left after the click.

Now I can send of the http-request via Javascript with the onbeforeunload event, but what happens to this http-request once the browser has left the page? Does it still "take the call" and places the cookie or does it ignore the call since the website from which the request originated is no more?

Could not find any documentation on this, so I'd be grateful if anyone had a clue.

Thanks,
Benjamin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒与心事 2024-08-16 00:48:04

如果您在发送 Http 请求后关闭浏览器(或单击不同的链接/页面),则该 Http 请求的响应将消失在黑洞中。事实上,Web 服务器实际上可能会也可能不会发送完整的响应,具体取决于所请求页面的大小以及请求套接字关闭的时间点。

If you close your browser (or click on a different link/page) after you have sent a Http request, the response from that Http Request will disappear into a black hole. Indeed, the web server may or may not actually send the full response depending on the size of the requested page and the point at which the requesting socket was closed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文