0

I would like to know when the

  1. browser window is closed and not the tab
  2. and if possible, when the last tab with my app is closed

Following is the only thing i have found:

Clear local storage when the browser closes in angular

I have tried the mentioned code with both onBeforeUnload and beforeunload, it is not firing for me.

Here is the code:

import { Component, HostListener } from "@angular/core";

@Component({
    selector: 'app-root',
    templateUrl:"./app/app.component.html"
})

export class AppComponent {
    @HostListener("window:onbeforeunload",["$event"])
    clearLocalStorage(event){
        localStorage.clear();
    }
}

I am interested in clearing one item placed in storage at the very end.

Or should i use cookie, but will it go away after the last tab / browser has been closed? Here is the cookie example

How to create cookies in Angular 6?

learning...
  • 3,104
  • 10
  • 58
  • 96

1 Answers1

0

You will probably figured it out by now, but such a distinction is not possible. While for the user it doesn't appear like that, tabs and a new window are basically the same for Javascript. The browser simply handles requests differently based on its configuration.

ak.leimrey
  • 1,137
  • 2
  • 11
  • 25