0

If the user switches tab or open other applications, I want to throw an error message

How to do this in JavaScript? (I'm using Angular) Thanks in advance

Anjana
  • 366
  • 5
  • 21
  • 2
    Does this answer your question? [Detect If Browser Tab Has Focus](https://stackoverflow.com/questions/7389328/detect-if-browser-tab-has-focus) – Maxim Mazurok Apr 24 '20 at 07:05

1 Answers1

1

Question already answered here: Is there a way to detect if a browser window is not currently active?

Not specific to Angular but JS.

Terry
  • 577
  • 2
  • 5
  • I agree, but please, use "flag" option instead of answering – Maxim Mazurok Apr 24 '20 at 07:06
  • Actually, there is a 'angular way' of doing this, using [HostListener](https://angular.io/api/core/HostListener) –  Apr 24 '20 at 07:09
  • @MikeS. That's more 'angular way' of listening for `window` events, I think. Tab focus detection is not framework-specific unless there's a plugin to do that... – Maxim Mazurok Apr 24 '20 at 07:12