删除浏览器关闭时不在页面刷新上的cookie [英] Delete cookie on browser close not on page refresh

查看:78
本文介绍了删除浏览器关闭时不在页面刷新上的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多关于同样问题的帖子,但我没有得到确切的解决方案。我想使用javascript删除浏览器上的cookie或tab close事件。我已经制作了删除cookie功能并调用 onbeforeunload 事件。但我看到该事件也在页面刷新时调用我不想在页面刷新时删除cookie。我在很多帖子中看到他们正在检测链接点击,F5的按键事件和表单提交,并且他们阻止 onbeforeunload 事件。但那么刷新按钮点击怎么样,然后在网址栏输入。所以我认为这不是一个确切的解决方案。所以请帮我解决这个问题。

I seen many post regarding same problem but i am not getting exact solution. i want to delete cookie on browser or tab close event using javascript. I have made delete cookie function and called on onbeforeunload event. But i seen that event also called when page refresh i dont want to delete cookie on page refresh. And i seen in many post that they are detecting link click, keypress event of F5 and form submit and in that they preventing onbeforeunload event. But then what about refresh button click and press enter at url bar. So i think this is not a exact solution. so help me out from this problem.

更多信息是我正在使用PHP创建cookie并希望在浏览器关闭时删除此cookie。

Further information is i am creating cookie using PHP and want to delete this cookie on browser close.

推荐答案

除非您为Cookie指定生命周期,否则Cookie会在浏览器关闭时自动删除。

Cookies are automatically deleted when the browser is closed, unless you specify a lifetime for the cookie.

这篇关于删除浏览器关闭时不在页面刷新上的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆