Does anyone know of a library that determines if pushState can be used?
I was using this:
if(window.history.pushState){
window.history.pushState(
pushState is part of the HTML5 History API. You can test for support using regular JavaScript like so:
if (typeof history.pushState !== "undefined") {
// pushState is supported!
}
Alternatively, you can use the Modernizr library:
if (Modernizr.history) {
// pushState is supported!
}
Looking at the Modernizer source code this is how it checks for push state:
tests['history'] = function() {
return !!(window.history && history.pushState);
};
So a simple way for you would just be:
var hasPushstate = !!(window.history && history.pushState);
One must first check for the existence of window.history before going two levels deep and that's probably why you were experiencing an error.