改善键盘导航的浏览器小调整
A small change to improve browsers for keyboard navigation

原始链接: https://b.43z.one/2025-07-22/

## Firefox 键盘导航增强 此扩展解决了 Firefox(和 Chrome)键盘导航中令人沮丧的限制。虽然 Firefox 的“快速查找”(’)会突出显示链接,但标准查找功能(/ 或 Ctrl+F)会突出显示*所有*文本,但按下突出显示的文本上的 Enter 键没有任何作用——不像链接。 该扩展通过添加一个简单的脚本来解决此问题,当在文本选择时按下 Enter 键时,**点击所选文本的父元素**。这有效地允许键盘用户“激活”按钮和 div,模拟鼠标点击,并大大改善了对依赖于这些元素而非传统链接的现代网站的导航。 作者强调这是一个小但有影响的改变,使键盘导航功能更加强大。他们还开玩笑地请求 Mozilla 解决 Firefox 的资源使用问题!该扩展是一个轻量级的补丁,用于弥补浏览器功能的不足。

## 浏览器键盘导航:Hacker News 讨论 一个 Hacker News 讨论源于一篇帖子,强调了一个小的改动以改善浏览器键盘导航。核心问题是使网页元素——不仅仅是链接——可以通过键盘快捷键访问。 用户分享了各种增强体验的扩展程序,包括 **Vimium**(及其 Firefox 版本 **Vimium C**)、**Tridactyl**、**ShortCat**(适用于 macOS,提供跨应用的 Vimium 风格链接)、**Surfingkeys** 和 **Leopard Links**。 一些用户甚至创建了自己极简的扩展程序,理由是担心流行的选项过于臃肿。 对话揭示了浏览器(Firefox 与 Chrome)和元素(链接与按钮/span)之间的不一致性。 建议使用 **Ctrl+F + Escape + Enter** 作为一种解决方法,但并非普遍适用。 提出了可访问性问题,指出损坏的可访问性功能具有法律影响。 几位用户强调了语义化 HTML 和诸如标题地图之类的功能对于更好的键盘导航的重要性。 最后,网站劫持快速搜索键也被指出是一个日益严重的问题。
相关文章

原文
A Small Change To Improve Browsers for Keyboard Navigation
by h43z (hompage)
We choose to use Firefox, not because it's easy but because it's hard.
~ jfk probably

(This problem applies to Chrome too though)

If you want to navigate websites with the keyboard you can make use of the ' search feature (aka "quick find for links") in Firefox. Just press ' and start typing. Any link with the anchor text you type will get highlighted. Once you press enter, firefox will navigate to the link under the highlighted anchor text.

Too bad most websites nowadays don't use links for navigation and actions. They have buttons and divs and once you click them stuff happens. 

And here lies the limitation with the other two build-in find features. Though the / (quick find) and the ctrl+f (find in page) search will highlight any text (not just links), nothing will happen if you press enter on that highlighted text
(once you dismissed the search dialog with escape).

Test it for yourself. Hello this is a link to my homepage and this a link with javascript:alert(1)
here a button with an handler.
and here a span with an onclick handler
Wouldn't it be great if firefox would just, like you know, click on the highlighted text (browser created a selection) whenever I press enter?! YES IT WOULD and that's why I created this little extension. All it does is inject these lines. addEventListener('keydown', event => { if(event.key !== 'Enter') return // more cases that should not hook enter are to be discovered... if(event.shiftKey) return const elementWithSelection = getSelection()?.anchorNode?.parentElement if(!elementWithSelection) return elementWithSelection.click() getSelection()?.removeAllRanges() }) The code just gets the node that has the current selection. Then looks for the parent html element of that node and clicks it. Afterwards removes the selection. This tiny hack makes keyboard navigation just so much better ~ h43z

Oh and let's not forget to MAKE FIREFOX STOP BURNING THROUGH YOUR BATTERY AND CPU!
联系我们 contact @ memedata.com