Reputation: 1100
I want the Browser Tab Focus and Blur Event using HostListener.
Upvotes: 4
Views: 6993
Reputation: 1100
First Import HostListener
in your Component
import { HostListener } from '@angular/core';
Then put this code to get Tab Focus and Blur Event
export class AppComponent {
@HostListener('window:focus', ['$event'])
onFocus(event: FocusEvent): void {
// Do something
}
@HostListener('window:blur', ['$event'])
onBlur(event: FocusEvent): void {
// Do something
}
........
.....
}
Upvotes: 10