Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#13363 closed bug (cantfix)

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

Reported by: dark.panda@… 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.

Change History (10)

comment:1 Changed 10 years ago by dmethvin

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?

comment:2 Changed 10 years ago by dark.panda@…

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.

comment:3 Changed 10 years ago by dmethvin

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.

comment:4 Changed 10 years ago by L. David Baron <dbaron@…>

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?)

comment:5 Changed 10 years ago by dmethvin

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

comment:6 Changed 10 years ago by dark.panda@…

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.

comment:7 Changed 10 years ago by dmethvin

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.

comment:8 Changed 9 years ago by tycho@…

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.

comment:9 Changed 9 years ago by dmethvin

Cc: miketaylr added

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

comment:10 Changed 9 years ago by dmethvin

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

Note: See TracTickets for help on using tickets.