0

I want to logout() user session when user leave website by closing web browser. I am using below code to display alert if user closes browser.

Code:-

$(window).bind('beforeunload', function () {
    return '';
});

Now I want to find whether use user have clicked "Leave this page" button or not. So that I can logout that user.

I found some threads on Stack overflow, but none are useful on this scenario.

On browser close beforeunload - how to find if user selected "Stay" or "Leave"

jquery beforeunload when closing (not leaving) the page?

javascript before leaving the page

Community
  • 1
  • 1
Bit_hunter
  • 789
  • 2
  • 8
  • 25

1 Answers1

1

I found solution.

Code:-

$(window).bind('beforeunload', function () {
    return '';
});

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

Hope it will be useful to someone.

Bit_hunter
  • 789
  • 2
  • 8
  • 25