Deleting Cookies

At some point, you’re going to want to delete a cookie or many cookies in a cookie record. It’s fairly easy to do; one technique that works well is to simply set the cookie’s expiration date to a date in the past, which causes the browser to delete it automatically. Script 10.7 shows how to force your cookies to become stale.

To delete cookies:

1.
var cookieCt = 0;
This script is going to keep track of how many cookies we’ve deleted, so we start off by creating the cookieCt variable and setting it to zero.
2.
if (document.cookie != "" && confirm ("Do you want to delete the cookies?")) {
This test first checks to make sure that the cookie doesn’t contain a null value, that is, there are some cookies. If the test shows that the ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.