当用户同时离开页面时,http 请求会发生什么?
我想在客户端上保留一些信息,即单击了哪个元素,从而将信息保存在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在发送 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.