65.9K
CodeProject is changing. Read more.
Home

How to end user session when browser closed

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (6 votes)

Feb 8, 2011

CPOL
viewsIcon

17131

//Using MooToolswindow.addEvent('unload', Cookie.delete.pass('applicationCookie'));//using JavaScript by itself...//http://www.quirksmode.org/js/cookies.htmlvar eraser = function () { eraseCookie('applicationCookie'); };if(window.addEventListener) window.addEventListener('unload',...

//Using MooTools
window.addEvent('unload', Cookie.delete.pass('applicationCookie'));
//using JavaScript by itself...
//http://www.quirksmode.org/js/cookies.html
var eraser = function () { eraseCookie('applicationCookie'); };
if(window.addEventListener) window.addEventListener('unload', eraser, false); 
else if(window.attachEvent) window.attachEvent('onunload', eraser);
Your method removes all other events from unload of the body and is bad practice. In this example, I delete a cookie which is obviously something which can be done even easier but then the same can be said for your article. You could make an XMLHttpRequest instead of deleting a cookie and this would be the way to go.