Monday, August 13, 2007

Checking whether windows has focus or not

- first... set focus on the window first with window.focus
- then.. add event listener to the window onblur event :
window.onblur = afunction()
- you're set!

Issues:
onBlur =
called when lost focus
onFocus =
called when got focus

There are 2 big areas that may clashes with focus, namely <window> and document <body>. Normally we want to detect when the user is not 'looking' at the browser window, maybe while doing work in MS Word. But if the last focus was given to the <body>, not <window>, even when you are looking at the browser window (but with a body element, such as a textbox is currently in focus), the onBlur event for window will be triggered.

No comments: