Skip to content Skip to sidebar Skip to footer

Window.close() And The Beforeunload Event

I need to clear some session variables whenever user closes the browser window. The window can be closed in two ways: the normal way by pressing the window close button by pressin

Solution 1:

Try this

$(window).on('beforeunload', function(){
  return 'Are you sure you want to leave?';
});

$(window).on('unload', function(){
     logout();

});

This solution works in all browsers and I have tested it.


Post a Comment for "Window.close() And The Beforeunload Event"