views:

1566

answers:

1

Can I check if host page for a JavaScript is active by the browser's tab in IE7/FF/Opera?

Checking other tabs than the page where this JS runs would probably be a security risk though..

My other option is a method I remember by prototype to check if the mouse cursor is active, but it's not that accurate.

+6  A: 

You can attach the onBlur and onFocus events to the window; that will tell you if you have focus or not. I have tested this and it works. You cannot check another page, but you can definitely check your own.

geowa4
Maybe I misunderstood his question, but wasn't it about checking other tabs than the one the javascript is running in?
Georg
I think you misunderstood the question. There's only one question mark there and it seems to be about the current tab.
Nosredna
I think this requires a little creativity, as it is poorly worded. I think he wants how to check if his page's tab is the active one.
geowa4
Why would he care if another page the user has up is running jQuery (or some other js)?
geowa4
He wrote about "checking other tabs", therefore I thought he meant that.
Georg
I'd like to execute AJAX calls only if the user is actually looking at the window, so this would be a solution :-)
olemarius