hashchange
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
jQuery – hashchange event
You can detect if the browser supports the event by: if (“onhashchange” in window) { //… } See also: Detecting event support without browser sniffing Emulating onhashchange without setInterval window.onhashchange
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
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
How can I detect changes in location hash?
The only way to really do this (and is how the ‘reallysimplehistory’ does this), is by setting an interval that keeps checking the current hash, and comparing it against what it was before, we do this and let subscribers subscribe to a changed event that we fire if the hash changes.. its not perfect but … Read more