Skip to content

Browser back button history includes anchor clicks #31

Answered by allejo
zshn25 asked this question in Q&A
Discussion options

You must be logged in to vote

This would have to be something you do via JS. The concept would be to intercept any clicks on the anchors, and manage updating the URL yourself in a way that doesn't trigger the history functionality.

Here's an example of how you can achieve that behavior,

<style>
    .heading {
        margin-bottom: 90vh;
    }
</style>

<ul>
    <li><a href="#section-1">Section 1</a></li>
    <li><a href="#section-2">Section 2</a></li>
    <li><a href="#section-3">Section 3</a></li>
    <li><a href="#section-4">Section 4</a></li>
</ul>

<h1 class="heading" id="section-1">Section 1</h1>
<h1 class="heading" id="section-2">Section 2</h1>
<h1 class="heading" id="section-3">Section 3</h1>
<h1 class="heading" 

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@zshn25
Comment options

@allejo
Comment options

@zshn25
Comment options

Answer selected by allejo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants