I am using native HTML5 History API calls and I am aware of the cross brower compatibility issues, but in my specific use case, those doesn’t matter. For my limited needs, the browsers are behaving consistently & the table in the above link tells the same story. So I don’t really want to add another JS library on the page (History.js) but I definitely want it to fail gracefully in browsers which don’t support them. I don’t want them to throw JS errors.
For instance, IE (and I imagine other non-supporting browsers would too) throws this JS error: Object doesn't support property or method 'replaceState'
I tried doing this but it doesn’t work:
window.history = window.history || {};
if (jQuery.isEmptyObject(window.history)) {
window.history.prototype.replaceState = function(a,b,c) {};
window.history.prototype.pushState = function(a,b,c) {};
}
Check if
pushStateexists in the history object.