JavaScript: how to know if current window is active

hq9000's Avatar
Newbie Member
Hello colleagues,

I've got a question that might be silly, but anyway. How can i track the status of the window my JS script runs on? I mean how to know if this window is active or not.

I've tried to tie handlers to 'onfocus' and 'onblur' events of the <BODY>, but the behaviour is rather strange - 'onblur' handler is NOT invoked when I switch between windows using ALT+TAB keys, even more - in IE when i switch to this window - both onfocus and onblue methos are instantly invoked.

I guess that this approach is more suitable for handling user actions when filling a form or somethinh like it, and that there should be something much more tailored for tracking windows' status. Hope you can help me out to find it )))

A lot of thanks in advance!
pradeep's Avatar, Join Date: Apr 2005
Team Leader
try the onblur & onfocus on the window object not on body tag.