Click to See Complete Forum and Search --> : detect window's focus


azure_ss
08-06-2004, 10:39 AM
How can I detect if the window has the focus(current window) or not?Thanks

gil davis
08-06-2004, 12:45 PM
You cannot detect focus. It is an event, not an attribute.

BillyRay
08-06-2004, 01:58 PM
You can - at least in IE only :(

Use the "hasFocus" method:

if (document.hasFocus()) alert('Document has focus!');

You can read more here:

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/hasfocus.asp

However, you could do a cross-browser solution simply by trapping the window and doucment onfocus events, and setting a global variable to "true" (onblur it would be set to false).

Hope this helps,
Dan