How can I do something like "browserTab.onfocus = myFunction" by which I mean that "myFunction" would get control any time something in it's browser tab gains focus? E.g., when the user switches from a different browser tab or a non-browser window. I don't need to know what got focus, just that something did in that tab.
"window.onfocus = myFunction" with event capturing works fine except when the main window contains frames. Doing document.getElementById('iframeId').contentWindow.addEventListener('focus',myFunction,true) to add an onfocus handler to the iframe's document works in Firefox except when the frame's content comes from another site, which is my case and I cannot modify that site. I'd rather not poll using document.hasFocus().