Explaining the problem
I'm working with sockets, and I'd like to know how to place a notification only when the tab is out of focus.
That is, when the user is viewing the tab, it will not receive notifications, but if it leaves the tab, it will receive new notifications
What I really need is a function similar to .blur()
of Jquery, but this function needs to work as a listener , that is, it stays there always waiting for something to happen. The problem with .blur()
is that it fires only when the window loses focus.
$(window).blur(function(){
console.log("Isto será executado apenas quando eu clicar em outra tab")
}
Summarizing
I need a function that runs on tabs that are not in the user's focus as it receives new notifications in real time.
It can be Javascript or Jquery.