I've been some testing reserching for this other question, when I noticed something very peculiar. FF4/5 fail to fire the focus
jQuery event. The other question which might be considered a duplicate was closed and accepted without a real answer.
For the question itself, I tried the following simple bit of code:
$('#target').focusout(function() {
$(this).focus();
});
It works well in Chrome and in IE, but it fails on FF. Here's the jsFiddle for the lazy ones among us.
Can anyone explain this behavior? Or is it a known bug?
I think I ran into this before, and if I recall correctly it seemed to be some kind of reentrancy problem. My impression was that because FF is already in the process of transitioning focus, it won't let you initiate another focus transition. I believe my workaround was something like
$('#target').focusout(function() {
setTimeout(function() {
$(this).focus();
}, 0);
});
The manual says aboult .focus()
call
This method is a shortcut for .trigger('focus')
and from the .trigger()
topic
Although .trigger() simulates an event activation, complete with a synthesized event object, it does not perfectly replicate a naturally-occurring event.
So as I understand it, the call $(this).focus();
is supposed to trigger the OnFocus event (if there is one attached to the object) but is not quaranteed to actually set/change the focused object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With