JavaScript Deleting Cookies

Javascript facilitates multiple ways of deleting cookies. These are as follows:

1. Delete the cookie by using the expire attribute

document.cookie = 'name=Mahesh; expires=Sun, 19 May 2019 18:04:55 UTC'

2. Delete the cookie by using the max-age attribute

document.cookie = 'name=Vishal; max-age=7200'

3. Delete cookie explicitly by using a web browser Example:

<!DOCTYPE html>
<input type="button" value="set" onclick="setCookie()">
<input type="button" value="get" onclick="getCookie()">
function setCookie()
document.cookie="username = COOKIE;expires=Sun, 28 Nov 2018 13:15:00 UTC";
function getCookie()
alert("No Cookie here");
Please follow and like us:
Content Protection by