When I visit my_site.com/page.php#something
, the scroll position is the one of the element carrying this particular hashtag rather than the top of the page.
Executing window.scrollTo(0, 0);
doesn't change this fact. What can then?
EDIT: also tried accepted answer from How to disable anchor "jump" when loading a page?. Doesn't seem to work anymore.
What you have to do is store the hashtag for later use and then delete it so that the browser doesn't have anything to scroll to.
It is important that you do not put that part of the code in the $() or $(window).load() functions as it would be to late and the browser already have moved to the tag.
Having this HTML code:
You can avoid scrolling to the div element and instead scrolling to the top of the window by using this code:
EDIT:
You can try to add this: