37

How can I check if the browser you are using supports the HTML5 history api?

As you can see here http://caniuse.com/#search=history only chrome +ff4 and several others supports this and I wish to do something else if they cant support this.

How can I make some kind of an if statement for this checking?

Donald Duck
  • 6,488
  • 18
  • 59
  • 79
Karem
  • 16,343
  • 69
  • 163
  • 271

3 Answers3

79
if (window.history && window.history.pushState)

See also this All-In-One Almost-Alphabetical No-Bullshit Guide to Detecting Everything

Cory House
  • 11,526
  • 8
  • 65
  • 82
Gaurav
  • 11,988
  • 2
  • 33
  • 33
24

You can detect support for history management (as well as many other browser features) using Modernizr.

if (Modernizr.history)
Gelatin
  • 2,353
  • 1
  • 23
  • 29
  • 1
    Modernizr also adds `history` class to your root `html` tag and `no-history` if you don't. That's probably not particularly useful like other features such as `flexbox` but it would allow you to change css depending upon this feature if you really had a need for it – Simon_Weaver Jul 30 '14 at 02:21
0

You can use canisuse.js script to detect if your browsers supports history or not

caniuse.history()
Beka
  • 1,819
  • 5
  • 19
  • 26