Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

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

JavaScript tutorial

1 comment:

  1. Hello sir, Your content is Best from author sites. please give some Questions for practice according to tutorial.


It would be great if you can help share these free resources