Arun David Arun David - 1 year ago 82
jQuery Question

Check browser compatibility for HTML5 History API support?

Is there any way to check a browser whether it supports 'HTML5 History API' using JavaScript.

Do I have to check all the browsers and its versions with a long list of condition in if statement.
Or simply like checking any object of function using 'if' statement is enough???...


Checking for the existence of a pushState() method on the global history object should be sufficient.

function supports_history_api() {
  return !!(window.history && history.pushState);

For more general HTML 5 feature detection I'd look at Modernizer

This will insulate your code from the messy specifics of each test, making the code more readable and less error prone. With the Modernizer script on your page you'd just do:

if (Modernizr.history) {
  // history management works!
} else {
  // no history support :(
  // fall back to a scripted solution like History.js