On a site that has an anchor in the URL, when you first go to it in Chrome, it jumps to that anchor properly.
For example: https://plato.stanford.edu/entries/happiness/#HybAcc
But then, if you scroll up or down slightly, and you refresh the page, you are taken to where you had last scrolled to, rather than the anchor specified in the URL bar.
I would like to have the functionality to guarantee that when you go refresh the page, you are taken back to the anchor regardless of where you had just been scrolling.
I tried this code:
$( document ).ready(function() {
if (window.location.href.split('#')[1]) {
location.href = "#" + window.location.href.split('#')[1];
}
});
The code correctly bounces to me to the anchor when the page first loads, but then it (against my wishes) bounces me to the last scrollbar position. How can I prevent that unwanted bounce to my last scrollbar position from happening? Thanks.