Check to see if window is in focus.

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 :) )
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

    <script type="text/javascript">
      function focused( aVal )
        var elem = document.getElementById( 'stat' ) ;
        elem.innerHTML = aVal ? 'WINDOW IS FOCUSED' : 'WINDOW IS NOT FOCUSED' ;
  <body onfocus="focused( true )" onblur="focused( false )">
    <div id="stat">

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mnb93Author Commented:
Hm... It requires me to click on the page though. Is it possible to make it work without the initial click?
TimYatesCommented: for me on both IE and Firefox...
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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)

mnb93Author Commented:
Don't worrie I fixed it.
mnb93Author Commented:
Well, not fixed it but I got what I wanted :)
Cool :-)  What did you do?

mnb93Author Commented:
Nothing, lol.
I it originally didn't work, and now it does work exactly how it should! :)
Yay! :-)

Good luck with it!

And thanks!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.