2

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.

2
  • If it works for him, why wait? :-) Commented Feb 4, 2009 at 18:04
  • mainly wait as the guy who answered provided an answer to a different question. in this case, an accept was granted for saying what was said in the question. someone else can prove that wrong later, as happened in this case. Commented Feb 4, 2009 at 19:05

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Maybe I misunderstood his question, but wasn't it about checking other tabs than the one the javascript is running in?
I think you misunderstood the question. There's only one question mark there and it seems to be about the current tab.
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.
Why would he care if another page the user has up is running jQuery (or some other js)?
I'd like to execute AJAX calls only if the user is actually looking at the window, so this would be a solution :-)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.