We are trying to clear the cookie details in browser on pressing 'Logout' button with the following code, but the script doesn't remove the session cookie from the browser. But by clearing the session cookies in IE8 browser using developer tool(Tools > Developer Tools >Cache > Clear Session Cookies), the cookies are cleared.
<html:link page="/home.do" onclick="logout();">
<html:img page="/images/logout.jpg"/>
</html:link>
function logout(){
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookiename = cookies[i].split("=");
var d = new Date();
d.setDate(d.getDate() - 4);
var expires = ";expires="+d;
var value="";
document.cookie = cookiename + "=" + value + expires + ";";
}
}
How to clear the Session cookies from the browser using script?