Firefox中的accesskey

应该有包括我在内的很多人有键盘快捷的习惯,在 Web 中,只要定义了 Access Key 的事件都可以用键盘快捷来进行触发。这话如果有点抽象,举一些实例你就很容易明白:比如大部分论坛你写完稿要提交时,你可以不用再把手移至鼠标去点击 submit 按钮,而直接用 alt+s(有的是 alt+enter)来完成。在这里,s 就是定义好的 Access Key。在 wordpress 的后台撰写中,所有的 quicktags 都有键盘快捷的 access key,以我自己为例,一般习惯先在纯文本编辑器上完成文字撰写后,再 copy 至 wordpress 后台撰写的文本框内,很多时候,这些文本需要格式来装饰,就需要添加 html tag,我的习惯是全部用键盘来完成,比如选定一段文字按 alt+l 就为这段文字添加了嵌套好的 <li> 标签; alt+a 就添加一个链接 <a> 。

而当我们安装了 Firefox  后会发现,alt+(accesskey)触发的不再是内容快捷而成了浏览器菜单快捷。这是 Firefox 的 Bug 还是它有意为之?我试图搜索一些官方资料来证明。

先来看看 W3C 对 Access Key 的官方描述:

The invocation of access keys depends on the underlying system. For instance, on machines running MS Windows, one generally has to press the “alt” key in addition to the access key. On Apple systems, one generally has to press the “ctrl” key in addition to the access key.

The rendering of access keys depends on the user agent. We recommend that authors include the access key in label text or wherever the access key is to apply. User agents should render the value of an access key in such a way as to emphasize its role and to distinguish it from other characters (e.g., by underlining it).

很清楚,触发 Access Key 是使用 Alt 还是其它键取决于 user agent,除 MacOS 的 safafi 外,一般都习惯分配 alt 键。

弄明白这个我们便可以去 Mozillazine 找到答案,看看 Firefox  中是如何定义的: firefox 地址栏键入 about:config,filter 键入 ui.key.contentAccess,尽管上面给出的 mozillazine 页面对各整数值的解释不全,可我们还是在 mozillazine forum 找到了完整的定义:

  • * 1 = Shift
  • * 2 = Ctrl
  • * 3 = Shift + Ctrl
  • * 4 = Alt
  • * 5 = Shift + Alt
  • * 6 = Alt + Ctrl
  • * 7 = Ctrl + Shift + Alt

解决方案

可以看到,Firefox  的 Ui.key.contentAccess 默认值是 5,说明官方将 AccessKey 的触发键改为了 shift+alt,并非新版本的 Bug,那解决的方法就很简单了(二选一):

1. 改变你的习惯,换用 shift+alt
2. 将整数值改回 4

原文地址: http://www.valu.cn/b90/d202768.aspx

XeonWell Studio