# 在新标签页中打开“键盘快捷键”会打开你点击“键盘快捷键”时所在的同一页面

**URL:** <https://meta.discourse.org/t/opening-keyboard-shortcuts-in-a-new-tab-opens-the-same-page-you-were-on-when-you-clicked-on-keyboard-shortcuts/132071>\
**Category:** UX\
**Tags:** keyboard-shortcuts\
**Created:** [2019年十月28日 15:02 UTC](https://meta.discourse.org/t/opening-keyboard-shortcuts-in-a-new-tab-opens-the-same-page-you-were-on-when-you-clicked-on-keyboard-shortcuts/132071 "2019-10-28T15:02:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![debryc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/debryc/32/101652_2.png) [@debryc](https://meta.discourse.org/u/debryc)\
**Post date:** [2019年十月28日 15:02 UTC](https://meta.discourse.org/t/opening-keyboard-shortcuts-in-a-new-tab-opens-the-same-page-you-were-on-when-you-clicked-on-keyboard-shortcuts/132071/1 "2019-10-28T15:02:07Z")

</div>

您好，我认为这更像是一个意外行为而非 Bug。

我在 Mac 上习惯于使用 ⌘+点击 在新标签页中打开链接。当我对汉堡菜单中的“键盘快捷键”执行此操作时，会打开一个新标签页，但该页面并未显示键盘快捷键。

---

<div class="post-metadata">

**Author:** ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)\
**Post date:** [2019年十月28日 15:14 UTC](https://meta.discourse.org/t/opening-keyboard-shortcuts-in-a-new-tab-opens-the-same-page-you-were-on-when-you-clicked-on-keyboard-shortcuts/132071/2 "2019-10-28T15:14:47Z")

</div>

该“链接”的导航由应用内处理。我之所以将_链接_加上引号，是因为它实际上并非真正的链接，因为它并不指向任何具体地址。

```plaintext
<a class="widget-link keyboard-shortcuts-link" href="" title="Keyboard Shortcuts">
  <span class="d-label">Keyboard Shortcuts</span>
</a>

```

注意到 `href` 属性是空的了吗？

它只是打开一个模态框或对话框。因此，无法在新标签页中打开该链接并显示该模态框。

---

<div class="post-metadata">

**Author:** ![debryc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/debryc/32/101652_2.png) [@debryc](https://meta.discourse.org/u/debryc)\
**Post date:** [2019年十月28日 15:55 UTC](https://meta.discourse.org/t/opening-keyboard-shortcuts-in-a-new-tab-opens-the-same-page-you-were-on-when-you-clicked-on-keyboard-shortcuts/132071/3 "2019-10-28T15:55:44Z")

</div>

你好，我明白了。我只是想指出，从_用户_的角度来看，这种行为是出乎意料的，因为“键盘快捷键”在视觉上看起来完全像一个链接。如果有办法提供一些提示，表明“在新标签页打开”的操作不会生效，那就最理想了。当然，我认为这不需要优先处理——我想不太会有太多人遇到这个问题。

---

<div class="post-metadata">

**Author:** ![lionel-rowe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lionel-rowe/32/134288_2.png) [@lionel-rowe](https://meta.discourse.org/u/lionel-rowe)\
**Post date:** [2019年十月31日 17:53 UTC](https://meta.discourse.org/t/opening-keyboard-shortcuts-in-a-new-tab-opens-the-same-page-you-were-on-when-you-clicked-on-keyboard-shortcuts/132071/4 "2019-10-31T17:53:15Z")

</div>

仅供参考，完全移除 `href` 属性（而不是将其设置为空字符串，后者是 [对当前文档的引用](https://stackoverflow.com/a/43340108)）应该可以防止链接在新标签页中打开，至少在大多数浏览器中是这样。

---

<div class="post-metadata">

**Author:** ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)\
**Post date:** [2019年十一月2日 08:36 UTC](https://meta.discourse.org/t/opening-keyboard-shortcuts-in-a-new-tab-opens-the-same-page-you-were-on-when-you-clicked-on-keyboard-shortcuts/132071/5 "2019-11-02T08:36:36Z")

</div>

有道理，在 HTML5 中，没有 `href` 的锚标签是有效的。

但移除它的问题在于，这会将其从 Tab 键索引中移除，导致无法通过键盘或其他辅助输入方式访问该链接。

我们可以通过添加 `tabindex: 0` 来解决这个问题。

因此，我们可以这样做：

```plaintext
links.push({
  action: "showKeyboard",
  className: "keyboard-shortcuts-link",
  label: "keyboard_shortcuts_help.title",
  attributes: {
    tabindex: 0
  }
});

```

除非 @awesomerobot 知道移除 `href` 还存在其他问题？

---

<div class="post-metadata">

**Author:** ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)\
**Post date:** [2019年十一月4日 20:24 UTC](https://meta.discourse.org/t/opening-keyboard-shortcuts-in-a-new-tab-opens-the-same-page-you-were-on-when-you-clicked-on-keyboard-shortcuts/132071/6 "2019-11-04T20:24:25Z")

</div>

我觉得这比起在新标签页中打开略有改进，但当我尝试在新标签页中打开该链接时，仍然感觉有些奇怪……尤其是因为这是菜单中唯一表现如此异常的链接。

理想情况下，无论何种情况都应打开键盘模态框。在 `/widgets/link.js.es6` 中，我们有：

```plaintext
click(e) {
  if (wantsNewWindow(e)) {
    return;
  }
  ...

```

看来，如果请求在新窗口/标签页中打开，我们在那里会阻止点击时的任何操作？……我在想，我们是否可以在那里做一些重组，以便即使在使用修饰键时也能打开模态框？

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2023年七月24日 14:12 UTC](https://meta.discourse.org/t/opening-keyboard-shortcuts-in-a-new-tab-opens-the-same-page-you-were-on-when-you-clicked-on-keyboard-shortcuts/132071/8 "2023-07-24T14:12:55Z")

</div>


