I am trying to detect when a text input field is active. I had originally implemented using onfocu
s, however, when the window is no longer the foreground window, the onblur
event is triggered. This has unintended consequences in my application. There id the DOMActivate
event which is fired, but in firefox this is NOT fired on text:input
fields.
Only one element can be active at a time in a document. An active element does not necessarily have focus, but an element with focus is always the active element in a document. For example, an active element within a window that is not the foreground window has no focus.
Fires: button, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:reset, input:submit
Does not fire: input:text, select, textarea
I have also tested using the input
event. However, this event is only fired if you actually type in the box. For my application, I need to capture when the text input field is active before anything it typed and it cannot change status when when then window is not in foreground.
I think there may be a way to do this with a mutation observer and then checking if that mutated element has activeElement
, but that seems like it will need more overhead. I do not think there is an event for lostActiveElement, so that would also add some extra tracking. Is there a more direct / efficient way to do this?
This is in a firefox add-on using addon sdk.