最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to destroy cookies on page refresh - Stack Overflow

programmeradmin2浏览0评论

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??

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??

Share Improve this question asked Jul 29, 2010 at 17:07 saisai 5,1674 gold badges25 silver badges19 bronze badges 3
  • If you rewrite the cookies the old values disappear. – mplungjan Commented Jul 29, 2010 at 17:16
  • well what would the event be, when I rewrite my cookies?? – sai Commented Jul 29, 2010 at 17:22
  • if your page loads after onunload then you are refreshing so you could test the age of a cookie you set in onunload and onload see if it is less than a minute old, you refreshed – mplungjan Commented Jul 29, 2010 at 17:51
Add a ment  | 

2 Answers 2

Reset to default 3

May be you could remove cookies on page unload.

For example, with jQuery:

$(window).unload(function() {
  //Destroy cookies here
});

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.

发布评论

评论列表(0)

  1. 暂无评论