How can I handle browser tab close event in Angular? Only close, not refresh

后端 未结 5 1974
时光取名叫无心
时光取名叫无心 2020-11-30 09:52

My goal is remove user cookies when browser tab closed.

Is it possible? Can I handle browser tab close event without refresh case?

If I use beforeunlo

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 10:19

    If your goal is to remove cookies when the browser is closed, don't set expiration. Cookies without expiration are removed when the browser closes.

    You really should never need to know if a user closes their browser or not. I'm confident there are alternative ways to accomplish whatever it is you're wanting to do.

    The Bottom Line:

    If a visitor is not on your page anymore, it really is none of your business what the user is doing with their browser or their computer. So detecting browser close will likely never be implemented without some kind of opting-in from the user, e.g., browser extensions/plugins.

提交回复
热议问题