0

I would like to logout user immediately on close browser window.

window.onbeforeunload = function () {
    if (user.isLoggedIn && expireOnCloseWindow) {
      user.logout();
    }
};

The event works OK for close window/tab, the event is fired and user is logged out. But event will fire also on page reload, what I want to prevent.

Does exists any way for logout on window close but prevent logout on page reload?

Edit1: It seems to be that performance.navigation is set after load the page and on beforeunload event is still with the same performance.navigation.type value.

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
    window.onbeforeunload = function () {
        let navOnject = performance.navigation;
        console.log(navOnject);

        if(navOnject.type !== navOnject.TYPE_RELOAD) {
            console.log('not reload');
        } else {
            console.log('reload');
        }
        return '';
    };
</script>
</body>
</html>
klaucode
  • 180
  • 1
  • 10

0 Answers0