Smooth scroll to anchor does not update browser URL

I’m using wpforo forum software. It has anchors for individual posts. Clicking on the anchor smooth scrolls to the right position, however, the URL HREF isn’t updated.

How can I add a ‘location.hash = [anchor];’ so the URL is updated correctly? As it is, I need to right click the anchor to get it’s URL that can be pasted elsewhere.

Hi There,

Thanks for writing in!

can you please point us to the page where you have the links with the smooth scroll. I did check the forum page and it has linked with hashtag but it goes to the post page and the section of the hashtag. Also in the URL, the hashtag is showing.

Please confirm if you are looking something different.

Thanks

Please go to the forum, click on a topic, then select the post anchor in the top right corner. Clicking on it will smooth scroll to it but won’t update the browser URL, so can’t copy & paste that point easily.

Hence how to fix this?

Hey @theitsage,

Does the functionality of your plugin work in other themes? Please try this solution. Add this code in Pro > Theme Options > JS.

jQuery("a").click(function(e){ 
  window.location.hash = this.hash;
});

See the effect https://youtu.be/i-whJV9uN7U

Just note that though that this should be treated as temporary fix. This might break in the future or might not play well with other scripts. In that case, you must contact a third party developer to further enhance the code. Please tell us if Pro is causing this though so we will forward this to our issue tracker.

Thanks.

1 Like

Thank you for the fix. It works.

Yes indeed, the interaction with wpforo + Pro’s smooth scroll causes this problem. If you peruse the wpforo forum site where smooth scroll isn’t used, the anchoring works fine:

Perhaps something to fix in a future Pro version?

Thanks for testing. I see a related issue in our bug tracker so I’ll add this case there.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.