I need to delete a cookie when the browser is closed and already placed in window.onbeforeunload along with another one of the following:
window.onbeforeunload = function(){ location.replace("admin.jsp?action=logout"); deleteCookie('Times'); }
with setCookie as follows:
function setCookie(name,value,days) { var expires; if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); expires = "; expires="+date.toGMTString(); } else { expires = ""; } document.cookie = name+"="+value+expires+"; path=/"; }
when it comes to deleteCookie, it contains the following:
setCookie(name,value,-1);
The problem is that when I restart the browser, it always comes to window.onbeforeunload, so deleteCookie starts. I really need this before resetting my countdown timer whenever the user logs in, since the cookie is never deleted if the counter does not end, and the user sometimes closes the window / tab before it ends. So my idea is to either reset the counter when the user logs in or just delete the cookie when the user logs out. However, I still cannot figure out how to code this. Can someone help me? However, the code snippet will be appreciated. CMIIW
source share