How to delete cookies with JavaScript

There is no delete function for cookies. You have to set it in the past.

Here's a function to do just that, set a cookie by its name in the past.

function delete_cookie(name) { document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;'; }

You might also need to add the domain in certain scenarios:

function delete_cookie(name) { document.cookie = name +'=; Path=/; Domain=.example.com; Expires=Thu, 01 Jan 1970 00:00:01 GMT;'; }

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*