JQuery: how can I find out when a tab / window gets focus?

Is there an event that I can register for this, every time a user clicks on a tab, which means that they were on my page tab, clicked on another tab, and then returned to my tab.

EDIT: By tabs, I mean browser tabs, not jQueryUI tabs.

+6
source share
2 answers

Matijis provided this answer in a comment, but I wanted to accept it, so here it is as an answer.

$(window).on('focus', function() { // your code }); 
+8
source

Try using jquery $ (selector) .focusin or: focus, they work the same.

http://api.jquery.com/focusin/

http://api.jquery.com/focus-selector/

+2
source

Source: https://habr.com/ru/post/908916/


All Articles