Browser back button does not work for Anchor links

css, html, javascript, jquery

Solution

I also faced the same problem see my question anchor links referring to the page sections not working on browser refresh, back and forward

But I had to do it the way normal links work so what I did was I manually go to that section by getting the element from the hash.

$(window).on('hashchange', function () 
{
    var top = $(window.location.hash).offset().top;
    $(window).scrollTop(top);
});

This works for forward and back buttons. And for refresh also you need to do the same thing. Get the element from the hash and scroll to that element manually.

Problem

In the footer of my page there a few links that point to different sections on the same page using anchor tags (# appended to the URL of the page). This works fine, just the browser back button does not work: I cannot move back to the previous page from where I had navigated to the anchored page. The simple question here is, is it possible to move back to previous page after navigating in the anchored page a few times? If it is then please could you suggest how? Anchored page: the page that has several sections marked by the id attribute that can be pointed to by a URL with `#anchorId` at the end.

Original source