How to keep the browser history in sync when using Ajax?

Update: There is now the HTML5 History API (pushState, popState) which deprecates the HTML4 hashchange functionality. History.js provides cross-browser compatibility and an optional hashchange fallback for HTML4 browsers. The answer for this question will be more or less the same as my answers for these questions: How to show Ajax requests in URL? How does … Read more

Handle URL fragment identifier (anchor) change event in Javascript

Google Custom Search Engines use a timer to check the hash against a previous value, whilst the child iframe on a seperate domain updates the parent’s location hash to contain the size of the iframe document’s body. When the timer catches the change, the parent can resize the iframe to match that of the body … Read more

Detecting Back Button/Hash Change in URL

The answers here are all quite old. In the HTML5 world, you should the use onpopstate event. window.onpopstate = function(event) { alert(“location: ” + document.location + “, state: ” + JSON.stringify(event.state)); }; Or: window.addEventListener(‘popstate’, function(event) { alert(“location: ” + document.location + “, state: ” + JSON.stringify(event.state)); }); The latter snippet allows multiple event handlers to … Read more

Change the URL in the browser without loading the new page using JavaScript

If you want it to work in browsers that don’t support history.pushState and history.popState yet, the “old” way is to set the fragment identifier, which won’t cause a page reload. The basic idea is to set the window.location.hash property to a value that contains whatever state information you need, then either use the window.onhashchange event, … Read more