Skip to main content

Bug Tracker

Side navigation

#13363 closed bug (cantfix)

Opened January 31, 2013 08:07PM UTC

Closed January 31, 2013 11:42PM UTC

Last modified December 18, 2013 04:59PM UTC

Firefox focus and blur events not firing when calling focus() and blur()

Reported by: dark.panda@gmail.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc: miketaylr
Blocked by: Blocking:
Description

I've set up a jsfiddle to illustrate the issue at http://jsfiddle.net/vKDe2/3/ .

The basic gist is that setting up focus and blur events on a text box and then calling focus() and blur() has no effect in Firefox 18.0.1 on the first call. Subsequent calls to focus() and blur() the events fire in Firefox, but the original call does not produce an alert.

In the latest Chrome, Safari, Opera and IE9 the aforementioned jsfiddle all produce alerts saying "focused!" and then "blurred!", but no alert is ever produced in Firefox 18. The jsfiddle is configured to use jQuery 1.9.0, but I have tested against 1.9-stable and master from git as well.

Attachments (0)
Change History (10)

Changed January 31, 2013 08:21PM UTC by dmethvin comment:1

The problem is that Firefox isn't setting the focus. Here's an example without jQuery at all:

http://jsfiddle.net/vKDe2/9/

The reason this changed is that we are now using the native focus/blur handler so that events occur in their correct "natural" order, for example if you focus an input and something else is currently focused, the blur handler for that something else should run before the focus handler on the new input.

If you just need to make sure that the jQuery handlers run, you can use .triggerHandler("focus"). If you actually need to set the little cursory thingy into the input box, only Firefox could fix that I think. Anyone else have other suggested solutions?

Changed January 31, 2013 08:29PM UTC by dark.panda@gmail.com comment:2

Ah, I see. I had read the upgrade guide and it mentioned this "natural" order, but it seemed odd that Firefox was the odd man out here. Using triggerHandler suits my purposes just fine, so from that perspective it's all good. Cheers.

Changed January 31, 2013 11:42PM UTC by dmethvin comment:3

resolution: → cantfix
status: newclosed

It's kind of hard to figure out how to close this. We can fix this particular issue as did 1.8.3 but only at the expense of reopening several other bugs closed in 1.9.0. Since it only affects Firefox, is clearly their bug, and does have a workaround with .triggerHandler() I'll close it cantfix. I would file a bug at Bugzilla but there are so many existing focus-related bugs that I am nearly sure it would be a duplicate.

Changed February 24, 2013 03:46AM UTC by L. David Baron <dbaron@dbaron.org> comment:4

So if I save the jsFiddle-generated file (i.e., save the lower right frame) to outside of jsFiddle's harness, I don't see the bug. So it's not clear to me whether this is a Firefox bug or something that jsFiddle is doing. (Does jsFiddle have browser-specific focus-related code in it?)

Changed February 26, 2013 06:35PM UTC by dmethvin comment:5

I think a lot of these focus-related issues only occur when the page is iframe-d.

Changed February 26, 2013 06:43PM UTC by dark.panda@gmail.com comment:6

In the situation where I had originally found and posted the ticket, we definitely weren't running in an iframe, we were running a series of jasmine tests.

Changed April 05, 2013 05:32PM UTC by dmethvin comment:7

The other place where I have seen this fail is when the Firefox browser window itself doesn't have focus, then the script's attempt to set focus to the input will fail as well. I suspect this is related to why it fails in an iframe, the parent has the focus. If it's failing in automated Jasmine tests that may be what's happening, we've seen it in Browserstack tests for example.

Changed December 18, 2013 04:33PM UTC by tycho@100grams.nl comment:8

Hello Dmethvin, How did you solve the issue with the actual browser losing focus? As I cannot find a solution as if yet. I am trying to get a webapplication to work together with a plugin using javascript, however Firefox always loses focus on initial start-up.

Changed December 18, 2013 04:55PM UTC by dmethvin comment:9

cc: → miketaylr

You'd need to file a bug report with Mozilla. Be sure to have a good simple reproducible test case.

Changed December 18, 2013 04:59PM UTC by dmethvin comment:10

See also https://github.com/jquery/jquery/pull/1423 where we gave up on unit testing focus issues on Firefox.