Here is my function to unset cookie.
<a href="#" onclick="removeCookie();"><input type="submit" value="Log Out" style="cursor:pointer;"/></a>
function removeCookie() { //Logout var str = document.cookie; var username = str.replace(/(?:(?:^|.*;\s*)username\s*\=\s*([^;]*).*$)|^.*$/, "$1"); if (username) { document.cookie = "username=NULL"; alert(username); if (username == 'NULL') { window.location.href = 'login.html'; } } }
For the first time the value of the cookie is not being set to "NULL". Its working for the second time button click. Please show me if there is any error.Please help me .Thank you in advance.
document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)