Which browsers support the HTML5 History API?
This might help : http://caniuse.com/#search=history
This might help : http://caniuse.com/#search=history
if (window.history && window.history.pushState) See also this All-In-One Almost-Alphabetical No-Bullshit Guide to Detecting Everything
So the bottom line is that iOS has added its own security around the history API, meaning that you can’t use script to change the url. Only a user action can allow the history API to change the url – i.e. a click – as per Aral’s example. The workaround is to uses a hash … Read more
location.hash has a better support than the history.pushState method. The advantage of the pushState method is that you can bind a state to the history entry. If you don’t need this state object, I recommend to use the location.hash property, to have better compatibility with older browsers. location.hash=”new-hash”; console.log(history.state); // null or undefined history.pushState({extraData: “some … Read more
You must implement it yourself which is quite easy. When invoking pushState give the data object a unique incrementing id (uid). When onpopstate handler is invoked; check the state uid against a persistent variable containing the last state uid. Update the persistent variable with the current state uid. Do different actions depending on if state … Read more
if (history.pushState) { // supported. } Quickest test is to run this in the browser console to see if it’s supported: if (history.pushState) { alert(‘supported’); } Also notice that in FF typeof(history.pushState) returns “function”, while in IE it returns “undefined”
The short answer is that history.pushState (not History.pushState, which would throw an exception, the window part is optional) will never do what you suggest. If pages are refreshing, then it is caused by other things that you are doing (for example, you might have code running that goes to a new location in the case … Read more
The popstate only contains a state when there is one. When it goes like this: initial page loaded new page loaded, with state added via pushState back button pressed then there is no state, because the initial page was loaded regularly, not with pushState. As a result, the onpopstate event is fired with a state … Read more
I used to use this to also be notified of when pushState and replaceState are called: // Add this: var _wr = function(type) { var orig = history[type]; return function() { var rv = orig.apply(this, arguments); var e = new Event(type); e.arguments = arguments; window.dispatchEvent(e); return rv; }; }; history.pushState = _wr(‘pushState’), history.replaceState = _wr(‘replaceState’); … Read more
Take this small example – run fiddle: You have a page where a user can select a color. Every time they do, we generate a new history entry: function doPushState (color) { var state = {}, title = “Page title”, path = “/” + color; history.pushState(state, title, path); }; We leave the state object blank … Read more