Parsing URL hash/fragment identifier with JavaScript

Here it is, modified from this query string parser: function getHashParams() { var hashParams = {}; var e, a = /\+/g, // Regex for replacing addition symbol with a space r = /([^&;=]+)=?([^&;]*)/g, d = function (s) { return decodeURIComponent(s.replace(a, ” “)); }, q = window.location.hash.substring(1); while (e = r.exec(q)) hashParams[d(e[1])] = d(e[2]); return hashParams; … Read more

How does facebook rewrite the source URL of a page in the browser address bar?

It’s using HTML5’s new history.pushState() feature to allow the page to masquerade as being at a different URL to that from which it was originally fetched. This seems only to be supported by WebKit at the moment, which is why the rest of us are seeing ?v=wall#!/facebook?v=info instead of ?v=info. The feature allows dynamically-loaded pages … 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

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

Can you use hash navigation without affecting history?

location.replace(“#hash_value_here”); worked fine for me until I found that it doesn’t work on IOS Chrome. In which case, use: history.replaceState(undefined, undefined, “#hash_value”) history.replaceState() operates exactly like history.pushState() except that replaceState() modifies the current history entry instead of creating a new one. Remember to keep the # or the last part of the url will be … Read more