Click here to Skip to main content
16,016,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys... I would like to ask if anyone of you knows how to detect if your current page is the selected/active one? you see i have a script that detects if your page is now the selected tab... but i want a code that when the page finish loading the script will check if the page is the currently selected page... here is my code that check if your page is the selected tab...

C#
window.onfocus = function () {
    isActive = true;
 };

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


So i want when my page finish loading it will automatically detect if its the active page or not... how do i do this? base from this code which i copied on one of the site i did some searching... this code only works when you switch from one browser to another or switch from one tab page to another now my problem is if my page finish loading how do i detect if its the current selected tab or not?

I have set the variable isActive to be true on first load and it works fine "if the user stayed on that page". but the problem arises when the user refresh the page and switch to another tab before the page loaded then my variable isActive is automatically set to true even though the user is not viewing that page... anyone one knows a work around for this one? i already saw this link but its not what i was looking for http://stackoverflow.com/questions/1760250/how-to-tell-if-browser-tab-is-active
Posted
Updated 14-Dec-11 17:54pm
v2

1 solution

In my opinion you should do some thing strange.
for instance use onfocus and onmousemove together.
when onmosemove is called you are 100% sure that page is active
so do not set isActive=true on onFocus, replace it on onMousemove function.
best regards Jamal.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900