[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Check to see if window is in focus.

Posted on 2006-03-31
9
Medium Priority
?
842 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 :) )
0
Comment
Question by:mnb93
  • 5
  • 4
9 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 2000 total points
ID: 16340850
<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>
0
 
LVL 5

Author Comment

by:mnb93
ID: 16340873
Hm... It requires me to click on the page though. Is it possible to make it work without the initial click?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16340893
Strange...works for me on both IE and Firefox...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:TimYates
ID: 16340902
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
0
 
LVL 5

Author Comment

by:mnb93
ID: 16340904
Don't worrie I fixed it.
0
 
LVL 5

Author Comment

by:mnb93
ID: 16340910
Well, not fixed it but I got what I wanted :)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16340912
Cool :-)  What did you do?

Tim
0
 
LVL 5

Author Comment

by:mnb93
ID: 16340918
Nothing, lol.
I it originally didn't work, and now it does work exactly how it should! :)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16340922
Yay! :-)

Good luck with it!

And thanks!

Tim
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question