Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery how to check if browser tab/window the selected is on our page?

How do check if a the user has the browser's tab/window currently on our page

function userisonourpage()
{
//do something
}

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

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

Just like in many places u switch to the page and the title changes i know the title can be changed with : document.title but dont know how to implement those functions.

Thanks :D

like image 257
kritya Avatar asked Jul 02 '11 21:07

kritya


People also ask

How do I know which tab is selected in jQuery?

var selectedTab = $("#TabList"). tabs(). data("selected. tabs");

How do you check if window is active or not?

Launch the Command Prompt or PowerShell and type the command "slmgr /xpr." Press Enter and you should see a prompt saying whether your Windows machine is activated or not. Click or tap OK, and you are done.


1 Answers

You could do this:

$(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. Cheers

like image 106
Edgar Villegas Alvarado Avatar answered Nov 02 '22 06:11

Edgar Villegas Alvarado