We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Check to see if window is in focus.

mnb93
mnb93 asked
on
Medium Priority
871 Views
Last Modified: 2008-03-10
I would like a way to see if the user is looking at the window, and has not got it minimised or behind another one. (Hopefully will work with tabs :) )
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004
Commented:
<html>
  <head>
    <script type="text/javascript">
      function focused( aVal )
      {
        var elem = document.getElementById( 'stat' ) ;
        elem.innerHTML = aVal ? 'WINDOW IS FOCUSED' : 'WINDOW IS NOT FOCUSED' ;
      }
    </script>
  </head>
  <body onfocus="focused( true )" onblur="focused( false )">
    <div id="stat">
    </div>
  </body>
</html>

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Hm... It requires me to click on the page though. Is it possible to make it work without the initial click?
CERTIFIED EXPERT
Top Expert 2004

Commented:
Strange...works for me on both IE and Firefox...
CERTIFIED EXPERT
Top Expert 2004

Commented:
oh, I think I see what you mean...if the URL is focused, then is says NOT FOCUSED...

I don't know how to get round that...maybe someone else does?

However if you manage to get round that then chances are tabs will always say they are focused even when they aren't (as the window will be focused)

Tim

Author

Commented:
Don't worrie I fixed it.

Author

Commented:
Well, not fixed it but I got what I wanted :)
CERTIFIED EXPERT
Top Expert 2004

Commented:
Cool :-)  What did you do?

Tim

Author

Commented:
Nothing, lol.
I it originally didn't work, and now it does work exactly how it should! :)
CERTIFIED EXPERT
Top Expert 2004

Commented:
Yay! :-)

Good luck with it!

And thanks!

Tim
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.