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

**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:** 2\
**Page:** 2

<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:01 UTC](https://meta.discourse.org/t/configure-a-custom-sidebar-link-to-open-in-a-new-tab/267004/21 "2026-07-10T05:01:43Z")

</div>

我也将 `external_links_in_new_tab` 设置为 true，这对于 PDF 和大多数外部链接来说是合适的。但我希望将论坛与主站无缝集成，而主站有一个指向论坛的链接。

> [@HAWK](#):
>
> 通常的做法是将论坛托管在子域名上，并对其进行样式设计以匹配主站，包括导航栏。这样用户就可以比较顺畅地来回点击。

如果侧边栏在新标签页中打开主站，这就根本行不通。

如果我前往 #Marketplace，有没有什么解决办法？我应该提出什么需求？

---

<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");
        });
    });
  });

```

[上一頁](https://meta.discourse.org/t/configure-a-custom-sidebar-link-to-open-in-a-new-tab/267004.md?page=1)
