Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

Update and delete cookies

Suggested Videos
Part 68 - JavaScript cookie attributes
Part 69 - Store multiple key value pairs in a cookie
Part 70 - Set and get multiple cookies in JavaScript



In this video we will discuss
1. Updating a cookie
2. Deleting a cookie
3. Cookie limitations



Updating a cookie : To update a cookie, set a cookie with the same name again. The following code updates the color cookie with the New_Color if a cookie with name=color exists otherwise it creates a new cookie with that name.
document.cookie = "color=New_Color";

Deleting a cookie : To delete a cookie, set a cookie with max-age attribute set to a negative value
document.cookie = "color=red;max-age=-60";

If you are using a browser that supports expires attribute, then set the expires attribute to a date in the past.
document.cookie = "color=red;expires=Mon, 01 Jan 1900 01:00:00 UTC;";

Please note: Users can also use the browser interface to delete cookies anytime they want.

Cookie limitations : 
1. What is the maximum allowed cookie size per cookie
2. How many cookies are allowed per domain

The answers to these questions really depend on the browser you are using. The following website can be used to find out what the limits are
http://browsercookielimits.squawky.net

JavaScript tutorial

No comments:

Post a Comment

If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.