Ticket #4332 (closed bug: invalid)
window focus event doesn't trigger on IE6
| Reported by: | segalerez@… | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | event | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Example:
$(window).bind('focus',function() {
$.jGrowl('Focus');
});
Works prefectly in Firefox, IE6 behaves in an unexpected manner.
Sometimes it triggers if an input inside gets focus. sometimes not. Sometimes when I switch to the window using Alt+Tab, sometimes not.
Change History
comment:1 Changed 4 years ago by dmethvin
- Status changed from new to closed
- Resolution set to invalid
comment:2 Changed 4 years ago by segalerez@…
- Status changed from closed to reopened
- Resolution invalid deleted
I believe $(window).focus and $(window).blur should have special treatment - in IE using document.onfocusin and document.onfocusout.
See http://odondo.wordpress.com/2007/08/28/javascript-and-cross-browser-window-focus/
This is also an issue when the window have no form elements at all.
As a cross-browser library, jQuery should suggest a method of detecting when windows get/lose focus, the same way it does for mouseenter and mouseleave.
comment:3 Changed 4 years ago by dmethvin
That enhancement is already on the roadmap for 1.4 and I think there's already a ticket although I can't find it at the moment:
http://docs.jquery.com/JQuery_1.4_Roadmap
In any case, it won't get lost, and it's working as currently documented. The docs actually specify that focus/blur aren't supported:
comment:5 Changed 4 years ago by brandon
I don't believe this bug has anything to do with live as discussed in the comments.
This blog post might shed some light on a possible solution: http://www.thefutureoftheweb.com/blog/detect-browser-window-focus
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

IE doesn't bubble several form events, including focus. jQuery doesn't control that. For reference, the events supported by .live reliably bubble to window in IE.
http://docs.jquery.com/Events/live#typefn