Jquery, how to check the selected tab / browser window on our page?

How to check if a user has a browser tab / window currently on our page

function userisonourpage() { //do something } 

And when the user switches the tab / window to our page?

 function tabswitched() { //dom something here too } 

As in many places, you switch to the page and change the title, I know that the name can be changed using: document.title but I do not know how to implement these functions.

Thanks: D

+6
source share
1 answer

You can do it:

 $(document).ready(function(){ $([window, document]).focusin(function(){ //Your logic when the page gets active }).focusout(function(){ //Your logic when the page gets inactive }); }); 

Hope this helps. Greetings

+12
source

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


All Articles