Reloading a page; anchor link is being ignored and previous scroll position is favored?

browser, google-chrome, html, javascript

Solution

`window.location.href = "/this/url/#post-10";` will work on its own, there's no need to reload the page a second time, which will (to the best of my knowledge) favor the previous scroll position.

Problem

I have a form that does an ajax call, and on success, reloads the (same) page and jumps to the submitted data toward the bottom of the page using a URL hash/fragments. ``` window.location.href = "/this/url/#post-10"; window.location.reload(); ... <div id="post-10">...</div> ``` I notice that at least with Chrome, the previous scroll position is being favored over the anchor link I am providing - so the page reloads, succesfully jumps to my `id` anchor, but once the page is finished loading, it jumps up to where the scroll was on the previous page. Is this standard behaviour? Is the best approach to fixing this to simply force the pages position using `onLoad` or something similar?

Original source

Related problems