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
  • 8,409
  • 22
  • 75
  • 99
Karem
  • 17,615
  • 72
  • 178
  • 278

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
  • 14,235
  • 13
  • 70
  • 87
Gaurav
  • 12,662
  • 2
  • 36
  • 34
24

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

if (Modernizr.history)
Gelatin
  • 2,393
  • 1
  • 24
  • 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 Tomashvili
  • 2,171
  • 5
  • 21
  • 27