With the help of javascript, I have created deleteCookie() function. In the code given below, I have stored all the values in a single cookie and then used deleteCookie() function for deleting the cookie. When the cookie session expires, previous cookie will be overwritten and the new cookie (new one) will instantly be expired.
<script type="text/javascript">
var expired = new Date(today.getTime() - 24 * 3600 * 1000); // less 24 hours
function deleteCookie(name)
{
document.cookie=name + "=null; path=/; expires=" + expired.toGMTString();
}
</script>
Calls this function to deletes the cookies:-
<script type="text/javascript">
function clearCookies()
{
deleteCookie("field1");
deleteCookie("field2");
deleteCookie("field3");
deleteCookie("field4");
alert('Your cookies have been deleted!');
}
</script>
0 Comment(s)