Questions
Yes, window.onfocus and window.onblur should work for your scenario:
window.onfocus
window.onblur
http://www.thefutureoftheweb.com/blog/detect-browser-window-focus
~ Answered on 2011-09-12 14:20:41