ChatGPT解决这个技术问题 Extra ChatGPT

How to allow keyboard focus of links in Firefox?

Go to this ultra-simple fiddle in a Webkit browser and click on on of the inputs:

http://jsfiddle.net/eK4TT/

<input type="text">
<input type="text">
<input type="text">
<a href="#">my first link</a>
<a href="#">my second link</a>
<a href="#">my third link</a>

Then, notice that you can keyboard navigate through both the inputs and the links using the Tab key (and Shift+Tab to navigate in reverse order).

Now, look at the same fiddle in Firefox on Mac OS and do the same thing. The inputs receive focus, but the links won't receive focus. It's not a CSS display problem. The focus leaps from the last input to the URL bar.

I've tried endless combinations of tabindex declarations in the markup, and to no avail, e.g.:

http://jsfiddle.net/eK4TT/1/

What the heck is going on here? I will accept any answer that has:

a) a fiddle working in Firefox
b) an explanation of what exactly is going on here in Mozilla's head. It appears to contradict the spec.

Not sure what is going on, it may be a weird JSFiddle & FF bug. Try dropping all tabindexs, and put tabindex="-1" on all and only the links. I don't have access to FF to test.
nah it's a mac thing. see my answer...
Oh yeah. This behavior should also happen in Safari too, if you don't have "all controls" enabled or whatever. It isn't a Moz issue

d
doppelgreener

Ok, somebody explained this to me. It's a Mac problem. Mozilla is being true to operating system settings in Mac OS.

There are two distinct ways around this on the user side. Both seem to work:

In System Preferences → Keyboard, in the Shortcuts pane, check the “all controls” radio at the bottom. In Firefox, type "about:config" in the URL bar. There is no accessibility.tabfocus preference on the mac, so you'll have to make one. Right click in the window, create a new "integer" pref, and set it to 7.

Neither of these are terribly obvious. Also, neither of these are a server-side solution for developers, which is frustrating.


10.9 Mavericks: System Preferences > Keyboard > Shortcuts > 'All controls' radio button at the bottom of the pane.
I'm on Catalina and I had to perform both of these suggestions - updating the system preferences alone didn't seem to change anything in Firefox. Once I added the new preference to Firefox's about:config, Firefox finally allowed tab focusing. Thanks!
In MacOS Mojave (Version 10.14.6), I had to perform both suggestions as well. The system preference didn't change Firefox' behavior. Adding the new Firefox preference did the trick. It's pretty wild that hyperlink keyboard focus is not a default behavior in Firefox.
Side note: I had to quit/restart Firefox after changing the config in System Preferences. Also, for Safari, I had to Safari > Preferences > Advanced > Accessibility: [x] Press Tab to highlight each item on a webpage (this was in addition to setting it in System Preferences).
8 years later and (option 2) is still the answer. Fun times.
j
javabeangrinder

On MacOS Big Sur this is done like this:

Tick the checkbox Use keyboard navigation...

https://i.stack.imgur.com/FYrRR.png

I also didn't have to hack the about:config


You need a ff restart to have those changes applied
@tobi-or-not-tobi I don't remember having to do that but thank you for sharing!
I did not have to restart Firefox. The settings were applied successfully without doing that.
thx! this worked for me without restarting Firefox
c
cranmerjs

Anyone looking at the second method explained within the accepted answer:

In Firefox, type "about:config" in the URL bar. There is no accessibility.tabfocus preference on the mac, so you'll have to make one. Right click in the window, create a new "integer" pref, and set it to 7.

Be aware that there is already a preference named accessibility.tabfocus within the Firefox Developer Edtion which is a boolean.

You can change this to an integer by clicking on the trash icon and deleting the preference. This will then allow you to select the type you would like the preference to be and allow you to assign it a value afterwards.


T
Thai Truong

Thanks, I'm on Catalina, and the following works:

In Firefox, type "about:config" in the URL bar. There is no accessibility.tabfocus preference on the mac, so you'll have to make one. Right click in the window, create a new "integer" pref, and set it to 7.