javascript 如何在页面刷新时销毁 cookie
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3365178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to destroy cookies on page refresh
提问by sai
Hello I need to destroy javascript cookies on a page refresh. I need to set a new bunch of cookies on every page load which help me render the web page based on user options. Is there a method to destroy cookies on a page refresh??
您好,我需要在页面刷新时销毁 javascript cookie。我需要在每个页面加载时设置一组新的 cookie,这有助于我根据用户选项呈现网页。有没有办法在页面刷新时销毁 cookie?
回答by cesarnicola
May be you could remove cookies on page unload.
也许您可以在页面卸载时删除 cookie。
For example, with jQuery:
例如,使用 jQuery:
$(window).unload(function() {
//Destroy cookies here
});
回答by Sarfraz
You need to detect the page refresh, have a look at:
您需要检测页面刷新,看看:
Detecting Page Refreshes :: Using JavaScript on Client-Side
Once you know that, you should be able to delete the cookies.
知道这一点后,您应该能够删除 cookie。

