Is there a way to detect if a browser window is not currently active?

Since originally writing this answer, a new specification has reached recommendation status thanks to the W3C. The Page Visibility API (on MDN) now allows us to more accurately detect when a page is hidden to the user. document.addEventListener(“visibilitychange”, onchange); Current browser support: Chrome 13+ Internet Explorer 10+ Firefox 10+ Opera 12.10+ [read notes] The following code … Read more