CadeLewis
CadeLewis

Reputation: 83

How to delete Cookie after page has changed Javascript

Im going to add cookie to specific page using javascript as simple as this

document.cookie="username=John Doe";

i want to make them expire when user change that specific page[Navigate to another page]. how to do that

Upvotes: 2

Views: 974

Answers (1)

Ludovic Feltz
Ludovic Feltz

Reputation: 11916

Just set the cookie time to an expired date:

document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC";

see: JavaScript Cookies

Upvotes: 1

Related Questions