0

I want to detect when the user switches a tab in order to change the title area when they receive a new chat message with "x new messages"

I tried:

var isActive;    
window.onfocus = function(){  isActive = true;   };     
window.onblur = function(){   isActive = false;  };

This does not work for me. Also, it doesn't have to be tabs, I want to make sure it detects that the specific window is not focused then 'do something'.

All help is much appreciated!

BragDeal
  • 748
  • 2
  • 10
  • 25

1 Answers1

0

USE jQuery or Mootools for detecting

$(window).blur(function(e) {
    // Do Blur Actions Here
});
$(window).focus(function(e) {
    // Do Focus Actions Here
});

source: Event for when user switches browser tabs

Community
  • 1
  • 1
Nikita_Sp
  • 94
  • 4