0

I need to know if a browser tab is displayed on any monitor. I tried using "focus" and "blur", but "blur" unfortunately gets fired the moment the user clicks on anything other than the browser window. I need something that only fires when the browser tab is in the background.

window.onfocus = function () { 
  console.log('onfocus');
}; 

window.onblur = function () { 
  console.log('onblur');
}; 

With the code above, if I have the browser tab open on one monitor and then click on another monitor, "onblur" fires. This is not what I want to happen.

I am looking for an event that fires when the browser tab moves to the background (see image below for what I mean). If the user has 5 different Chrome windows open on 5 different monitors, then they could potentially have 5 different active/visible tabs.

enter image description here

Rainbolt
  • 3,542
  • 1
  • 20
  • 44

0 Answers0