Can I update window.location.hash without having the web page scroll?

To change the hash without having the page reload/scroll, you can now simply use html5 history.pushState. history.pushState(null,null,’#hashexample’); It’s supported by all the major browsers: http://caniuse.com/history MDN: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#The_pushState().C2.A0method Also note that the last url parameter we’re using here can be any url, so it’s not limited to hashes.

How to trigger browser’s back event/function using JavaScript?

history.back() should do the trick. window.history.back() documentation at MDN As an aside, it’s bad user experience if you do this unexpectedly on the user. For example, I enter in an invalid credit card number, and you take me back one page, instead of letting me fix the mistake. So while it’s possible to use javascript … Read more

React router, how to restore state after browser back button?

after a while I found a reasonable workaround: in react, after every this.setState() I keep state synchronized with history using window.history.replaceState({ key: history.location.key, state: this.state}) when a “page” component is mounted or refreshed (willMount and willReceiveProps) I check for state in props.params.location.state: if there is one, I do restore it; if there is none I … Read more

All-in-one location/hashchange history management library

I believe Sammy.js ( http://sammyjs.org) (MIT-licenced) has the best focus on what you want to do, with its 2 main pillars being: Routes Events I could quote from the docs but it’s pretty straightforward: setup clientside routes that relate to stuff to be done, e.g: update the view through ajax link events to call routes, … Read more