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
2 Answers
Reset to default 3May 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.