简体   繁体   English

检测浏览器关闭所有条件

[英]detecting browser close all conditions

This question has been asked many times before but none of the previous ones hit all the issues. 这个问题之前已被多次询问过,但之前没有一个问题涉及所有问题。 I have a shopping cart that I store in session state. 我有一个我在会话状态存储的购物车。 I'd like to detect when the user leaves the site so I can ask if they'd like to save their cart. 我想检测用户何时离开网站,以便我可以询问他们是否愿意保存他们的购物车。 I'd prefer not to automatically store the cart, I hate sites that I re-visit and there's all this leftover stuff in the cart that I'm no longer interested in. 我不想自动存放购物车,我讨厌我重新访问的网站,购物车中剩下的所有这些东西我都不再感兴趣了。

I've tried onbeforeunload but it fires when the user hits the back/previous buttons. 我已经尝试过onbeforeunload但是当用户点击后退/上一个按钮时它会触发。 Is there any way from within onbeforeunload I can determine the url where the browser will be going next? 在onbeforeunload中是否有任何方法我可以确定浏览器下一步的网址? Then I can check if it is local and ignore it, otherwise if leaving the site for good a prompt can be displayed. 然后我可以检查它是否是本地的并忽略它,否则如果离开网站好,则可以显示提示。

Maybe I am not getting something? 也许我没有得到什么? How do you handle this situation? 你是如何处理这种情况的?

How do you handle this situation? 你是如何处理这种情况的?

You don't. 你没有。

Use a session timeout to clear the shopping cart. 使用会话超时清除购物车。

Besides, what if the user accidentally closes the site? 此外,如果用户意外关闭该网站该怎么办? Their cart would automatically be cleared, which makes for terrible UX. 他们的购物车会被自动清理,这会导致可怕的用户体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM