views:

598

answers:

0

I need to know via javascript whether a page has focus or not.

When the user switches to another tab, minimizes the browser, or clicks outside the browser, the page shouldn't have focus.

When the user returns to the window, by opening it, returning to the tab, clicking on the page, the page needs to have focus.

The problem is the method must correctly report whether the page has focus or not when there is a flash swf on the page that may or may not have focus and I don't have control of the swf content.

The window's focus needs to be independent of the flash swf's focus. So when the swf has focus, the user leaves the browser whilst the flash swf has focus, or when the user returns directly to the swf, the window's focus must be reported correctly.

I have methods of doing this in FireFox 3.0, 3.5, IE 6, 7, 8, Safari 4.0.3, 4.0.4, Opera 9.0+.

The standard focus/blur window events do not work properly in Google Chrome. When the flash swf gains focus, the window loses it (the window blur event is triggered). This is not desired.

I need a method that will work in Google Chrome 3 and 4.

Ideally, I would also like a method that works in FireFox 2 and Safari < 4.0.3. In these browsers, focus/blur do not work either as if the flash swf has focus and you leave the window, the blur window event is not triggered at all.