# 移动设备上的 URL 哈希/锚点被剥离。如何阻止这种情况？

**URL:** <https://meta.discourse.org/t/hash-anchors-are-being-stripped-from-urls-on-mobile-how-to-stop-that/408505>\
**Category:** Support\
**Tags:** mobile\
**Created:** [2026年七月25日 09:10 UTC](https://meta.discourse.org/t/hash-anchors-are-being-stripped-from-urls-on-mobile-how-to-stop-that/408505 "2026-07-25T09:10:40Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![one1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/one1/32/493591_2.png) [@one1](https://meta.discourse.org/u/one1)\
**Post date:** [2026年七月26日 10:50 UTC](https://meta.discourse.org/t/hash-anchors-are-being-stripped-from-urls-on-mobile-how-to-stop-that/408505/3 "2026-07-26T10:50:15Z")

</div>

以下是一些相关的帖子，尽管它们没有解决 URL 被剥离的具体问题……

> [@主题内帖子中的锚点不起作用](https://meta.discourse.org/t/anchors-not-working-across-posts-within-topic/240512/):
>
> 我们正试图将一个主题设置为一种常见问题解答/论坛使用指南，在此过程中，我们希望有多个较长的帖子，每个帖子都有多个标题，并在主题的第一个帖子中编译一个目录，以便用户可以轻松地跳转。 这被证明是出乎意料地难以按预期工作，而且在 Meta（论坛）上挖掘也无济于事。我们知道插件（自动目录或类似的东西），但我们只想为这一个主题使用它，所以不想处理它。 我们尝试使用通过 # 符号自动生成的 markdown 标题旁边的链接图标，但这不起作用——我们不确定这是否仅仅是因为我们为标题使用的颜色，或者完全是其他原因，但无论如何，这对我们的一些标题有效，但并非全部。 尝试使用带有手动 ID 的 HTML 标签来设置标题也没有成功——这根本无法跳转到链接。我们在 Meta 上看到有人说 ID 信息被 Discourse 剥离了，因此停止了这种方法。 然后，我们看到一个巧妙的想法，即在标题上方放置空链接，您可以直接跳转到这些链接，尽管这起初似乎有效，但在我们发布了几个帖子后，它也停止跳转到链接帖子中的正确位置。 有人知道为什么标题似乎如此糟糕，以及如何让它们在单个主题内的多个帖子中起作用吗？我将此归…

> [@"/t/XYZ#anchor" 在 XYZ 页面上不起作用](https://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101):
>
> 你好！当帖子使用短链接 + 锚点 (/t/id#anchor) 链接到自身，并且在同一页面上点击该链接时，它会重定向到顶部而不是锚点，这里存在一个问题。 演示一下就更清楚了： Header 1 [#header-1](#header-1-1) 在此帖中点击时有效 \u003chttps://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101#header-1-1\u003e 在此帖中点击并引用时有效 \u003chttps://meta.discourse.org/t/a/225101#header-1-1\u003e 在此帖中点击并引用时有效 \u003chttps://meta.discourse.org/t/225101#header-1-1\u003e 在未在此帖中点击时有效 [/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101#header-1-1](https://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101#header-1-1) 在此帖中点击并引用时有效 [/t/a/225101#header-1-1](https://meta.discourse.org/t/a/225101#header-1-1) 在此帖中点击并引用时有效 [/…](https://meta.discourse.org/t/225101#header-1-1)

> [@如何白名单化任意 HTML 属性？](https://meta.discourse.org/t/guidance-whitelisting-arbitrary-html-attributes/123469):
>
> 显然，这里以前在 Meta 上有一个主题，可以指导你如何注入脚本，但已被移除。 起初，我不知道 Markdown 会剥离 HTML 帖子中的 id 和类，随后我又发现脚本的执行方式有所不同。 我试图让这个 CodePen 示例在 Discourse 站点中运行，但不确定从何入手，因为显然无法通过常规的复制/粘贴方式实现： 我明白只能从管理员端添加脚本，我也确实这样做了，但我认为还需要更多工作才能让它在主题内部正常运行。 基本上，这些外部脚本会被触发，向具有特定数据属性的 div 注入内容。 我是否必须用 jQuery 和 Ember 重写整个外部脚本来注入带有内容的 div？我希望不必重新发明轮子。 提前感谢，

> [@允许其他 HTML 元素](https://meta.discourse.org/t/allowing-additional-html-elements/203510):
>
> 在 [Whitelisting HTML tags / attributes](https://meta.discourse.org/t/whitelisting-html-tags-attributes/159653?u=freso) 中，Joffrey 链接到了 [https://github.com/discourse/discourse-policy/blob/main/assets/javascripts/lib/discourse-markdown/policy.js.es6#L43，介绍了如何白名单化指定的](https://github.com/discourse/discourse-policy/blob/main/assets/javascripts/lib/discourse-markdown/policy.js.es6#L43%EF%BC%8C%E4%BB%8B%E7%BB%8D%E4%BA%86%E5%A6%82%E4%BD%95%E7%99%BD%E5%90%8D%E5%8D%95%E5%8C%96%E6%8C%87%E5%AE%9A%E7%9A%84) HTML 标签和属性，但我在设置中并未找到任何名为 policy 的选项。 这是否已不再适用？或者我是否误解了该代码的工作原理？这是否需要我创建一个插件（或主题组件）来挂钩实现？

---

_[View the full topic](https://meta.discourse.org/t/hash-anchors-are-being-stripped-from-urls-on-mobile-how-to-stop-that/408505)._
