# 将自定义侧边栏链接配置为在新选项卡中打开

**URL:** <https://meta.discourse.org/t/configure-a-custom-sidebar-link-to-open-in-a-new-tab/267004>\
**Category:** Feature\
**Tags:** sidebar\
**Created:** [2023年六月1日 11:09 UTC](https://meta.discourse.org/t/configure-a-custom-sidebar-link-to-open-in-a-new-tab/267004 "2023-06-01T11:09:37Z")\
**Posts on this page:** 1\
**Showing post:** 22

<div class="post-metadata">

**Author:** ![markschmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markschmucker/32/141599_2.png) [@markschmucker](https://meta.discourse.org/u/markschmucker)\
**Post date:** [2026年七月10日 05:58 UTC](https://meta.discourse.org/t/configure-a-custom-sidebar-link-to-open-in-a-new-tab/267004/22 "2026-07-10T05:58:41Z")

</div>

我最终将这段代码添加到了我的自定义 JS 中：

```plaintext
  const MAIN_SITE = "https://www.main-site.com";

  api.onPageChange(() => {
    requestAnimationFrame(() => {
      document
        .querySelectorAll(`.sidebar-wrapper a[href^="${MAIN_SITE}"]`)
        .forEach((a) => {
          a.removeAttribute("target");
          a.removeAttribute("rel");
        });
    });
  });

```

---

_[View the full topic](https://meta.discourse.org/t/configure-a-custom-sidebar-link-to-open-in-a-new-tab/267004)._
