Linking links to sections of pages that do not work with browser updates, back and forth

I created an html page with links inside the page.

<div> <a href="#first">first</a> <a href="#second">second</a> <div id="first">First div</div> <div id="second">Second div</div> </div> 

But this code does not work on the update page and the browser back and forth. Does anyone know how to solve this problem. I am not looking for html5 api history and jquery history plugin. Want to create this in your base format.

+1
javascript jquery html html5 jquery-plugins
source share
1 answer

Well, I figured out how to do this after many attempts. Now it concerns my goal, so I will continue this decision.

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

This works for the forward and back buttons. And for the update, you also need to do the same. Get the item from the hash and manually select the item.

+1
source share

All Articles