one1 reports that URL anchors (hash fragments) are stripped on mobile browsers (Android Firefox & Chrome), preventing scroll-to-element navigation. This issue is particularly problematic for long guideline and FAQ documents where mobile users rely on anchor links for navigation. While a custom theme component works on desktop, mobile behavior removes the anchor, leaving users at the top of the page. Interestingly, links generated by the Table of Contents plugin work correctly on mobile.
one1 notes that query parameters survive on mobile but are stripped on desktop, creating an inconsistent user experience. Lilly suggests using standard Discourse header anchors (e.g., #p-738234-cloudflare-r2-13). However, one1 explains these dynamic anchors are fragile because they depend on the heading’s position in the document; adding new content earlier shifts the anchor ID, breaking external links. This is critical for FAQs where new questions are frequently added.
awesomerobot proposes using manual HTML anchors like <a name="cloudflare-r2"></a>. one1 notes that the Markdown cooker typically strips name attributes. awesomerobot suggests wrapping the anchor in a <div> (e.g., <div><a name="x"></a></div>) to preserve it in the rich text editor, as the Markdown editor might handle it differently. one1 confirms that wrapping anchors in <div> tags works in both editors and plans to test mobile behavior further. Finally, renato mentions that recent Discourse updates (PRs #44487 and #44498) may have improved anchor handling.
When I click on a link with an anchor on desktop, it scrolls there. However on mobile (Android, FF & Chrome) the anchor gets stripped from the url so there is no scrolling to that spot.
What I am trying to do:
We have a long guideline and faq document that need to link to headings. Because Discourse strips out id parameters, I have created a simple theme component that uses custom data attributes in the target document and listens for anchors in the url to scroll to the element with matching data element.
It works on desktop!
However on mobile, the anchors seem to get stripped so that when you get to the target page there is no scrolling to the right element. And of course with a long document Mobile is where you need that navigation the most.
Now, I do find that the anchors generated by the Table of Contents component do work when opening them in a new link. They are not stripped from the url and the browser scrolls to the right place.
i don’t use android so i can’t test this but i’ve used linking to headers many times and they work on my iphone just fine. i’m curious why you are using id anchors instead of just linking to the header you want?
See that -13 at the end? It’s there because it’s the thirteenth heading. As soon as you add a new heading earlier in the document it breaks. And of course if you change the text of the heading it breaks.
When I say breaks, I mean changes in the target document. From what I can tell those anchors are generated dynamically when the page is loaded. So if you are using the TOC plugin changing the document is not a problem.
In our use case, this is a FAQ being linked to. So it is not uncommon to add new questions/headings.
But you are correct that Discourse seems to detect the pattern of those anchors and allows them through. But if it doesn’t match the expected pattern then it gets stripped.
They are just ordinary alphanumeric ids. So if I were trying to create an anchor for your example above I would just use cloudflare-r2.
In my tests, the Markdown cooker strips out name attributes. This is the root of my first problem.
However, the issue I am raising in this topic is that even if I could get that anchor to work, on mobile the #cloudflare-r2 gets stripped off. It doesn’t on desktop.
Ah I see, yeah looks like the rich text editor strips those out but the markdown editor does not… in the rich editor I think you’d have to wrap it in a div so it preserves the HTML