[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

Detect whether window is active. cross-browser

Is there a way to detect if my browser page is the active page (as opposed to just a tab that the user has hasn't clicked on yet in their tabbed browsing activity). I want to turn off certain page monitoring if this is the case, but don't know how to detect for it.
0
metalaureate
Asked:
metalaureate
  • 3
  • 2
2 Solutions
 
HainKurtSr. System AnalystCommented:
you can try this

<script>
function msg(){alert("focused...")}
</script>

<body onFocus="msg()">
0
 
tdlewisCommented:
You really don't want to do that particular test! It will put your browser into an endless loop of showing the alert box.

You could use the snippet below and test hadFocus anywhere you want to know if the page had ever been displayed.
<script>
var hadFocus = false
</script>

...

<body onfocus="hadFocus=true">

Open in new window

0
 
metalaureateAuthor Commented:
http://www.w3schools.com/jsref/event_onfocus.asp

Body does not take the onfocus event. I need something else...
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
metalaureateAuthor Commented:
window.onfocus maybe?
0
 
tdlewisCommented:
I have tested body.onfocus in both Firefox 3.6 and Internet Explorer 6 and 8.
0
 
metalaureateAuthor Commented:
I'm FF 3.6.2 and I could not get it to work programmatically... however everything works fine if I use window.onfocus.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now