andrew Sullivan
andrew Sullivan

Reputation: 4084

delete cookies using javascript

I am working on Asp.Net Mvc and am creating a cookie using in one page.I want when a user moves to her page the cookie gets deleted.Further if the same page (in cookie was created) is refreshed the cookie should not be deleted.How can i achieve this.

Upvotes: 0

Views: 542

Answers (2)

Javid Jamae
Javid Jamae

Reputation: 9009

When you're creating the cookie, set the expires like this:

document.cookie="cookie_name=cookie_value; expires=Thu, 01-Jan-1970 00:00:01 GMT";

Upvotes: 1

jwueller
jwueller

Reputation: 30996

quirksmode.org has some pretty handy functions for creating/reading/manipulating/deleting cookies.

Upvotes: 1

Related Questions