The focus and blur events keep track of the elements the user focuses on.
That sounds simple, but it isn’t.
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3 | Saf 3.0 Win | Saf 3.1 Win | iPhone 3G | Opera 9.26 | Opera 9.51 | Konqueror 3.5.7 | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
On the window
|
Yes | Yes | Yes | No | Minimal | Yes | No | |||||||
|
Are the focus and blur events available on the window?
|
||||||||||||||
|
On the document
|
No | Too many | No | Yes | Minimal | |||||||||
|
Are the focus and blur events available on the document?
|
||||||||||||||
|
On links
There should be focus and blur events on the |
Yes | Too many | Yes | No | Incom |
No | No | Too many | Yes | |||||
|
Focus and blur events on links should always fire, regardless of whether the user uses the mouse or the keyboard.
|
||||||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3 | Saf 3.0 Win | Saf 3.1 Win | iPhone 3G | Opera 9.26 | Opera 9.51 | Konqueror 3.5.7 | ||
|
On form fields
There should be focus and blur events on the form field only. |
Yes | Too many | Yes | Incom |
Yes | Too many | Yes | |||||||
|
Focus and blur events on form fields should always fire, regardless of whether the user uses the mouse or the keyboard.
|
||||||||||||||
|
On focusable elements
By giving it a |
Yes | Yes | Untest |
Untest |
Yes | Untest |
||||||||
|
|
||||||||||||||
|
Focusing and blurring the entire window
This action should fire a focus and blur event on the window only. |
Yes | Almost | Too many | Too many | Yes | No | Incor |
Too many | No | |||||
|
If the user brings a browser window forward (by clicking on it, using Alt+Tab or manipulating the taskbar), a focus event on the window fires. Likewise, if the browser window loses focus, a blur event fires.
|
||||||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3 | Saf 3.0 Win | Saf 3.1 Win | iPhone 3G | Opera 9.26 | Opera 9.51 | Konqueror 3.5.7 | ||
|
Focusing and blurring the “default space”
No event should fire. Personally I feel that, if the “default space” should be represented at all, it should be
represented by just the |
Alter |
Yes | Probably | Yes | Untest |
Yes | Largely untestable | |||||||
|
What happens when the focus passes from a link or form field to the document in general, or vice versa? Suppose the focus is on a form field, and the user clicks nowhere in particular? The form field is blurred, but is anything focused? Or suppose the focus is on the document in general, and the user focuses on a link. The link is focused, but is anything blurred? I call the document area that is not a link or a form field the “default space”. There are two theories that explain the “default space’s” connection with the links and form fields it contains.
As you might have guessed, browsers disagree on which theory to follow:
|
||||||||||||||
|
Event bubbling
“No” is the correct answer
The focus and blur events do not bubble up. |
No | Incor |
No | No | No | No | ||||||||
|
Note that focus and blur events can be captured.
|
||||||||||||||
|
Prevent default
“No” is the correct answer
|
No | No | No | No | No | |||||||||
|
There is no default to prevent: the events are fired once the user has succesfully put the focus on an element. |
||||||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3 | Saf 3.0 Win | Saf 3.1 Win | iPhone 3G | Opera 9.26 | Opera 9.51 | Konqueror 3.5.7 | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
activate
Despite the name this event is an equivalent of focusin. |
Yes | No | No | No | No | |||||||||
|
deactivate
Despite the name this event is an equivalent of focusout. |
Yes | No | No | No | No | |||||||||
|
DOMFocusIn
As focus, but bubbles. |
No | No | No | Incom |
No | Yes | Yes | |||||||
|
||||||||||||||
|
DOMFocusOut
As blur, but bubbles. |
No | No | No | Incom |
No | Yes | Yes | |||||||
|
||||||||||||||
|
focusin
As focus, but bubbles. |
No | Yes | No | No | No | No | ||||||||
Not available on the window. |
||||||||||||||
|
focusout
As blur, but bubbles. |
No | Yes | No | No | No | No | ||||||||
Not available on the window. |
||||||||||||||
| Method or property | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3 | Saf 3.0 Win | Saf 3.1 Win | iPhone 3G | Opera 9.26 | Opera 9.51 | Konqueror 3.5.7 | ||