-1

I am developing a small game in js/jquery and I am looking for an event allowing to pause the function and timer when the player is not on the window or leave the window, do you know this event, I could not find it.

Thank you.

LeMarsh
  • 55
  • 7
  • 1
    Does this answer your question? [Is there a way to detect if a browser window is not currently active?](https://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active) – GrafiCode Sep 16 '21 at 13:01

1 Answers1

0

You're looking for the blur and focus events.

addEventListener('blur', function(){
  console.log('Window no longer active');
});

addEventListener('focus', function(){
  console.log('Window is now active');
});
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116