Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if browser is supporting js pushState function?

I want to use dynamic URL update through js script:

window.history.pushState("string", "Title", "/new-url");

But if browser is old and not supporing this function it should simply redirect to new URL.

Is there any simple way to check it ?

like image 831
Vovan Avatar asked Apr 01 '14 09:04

Vovan


2 Answers

You simply check:

if (history.pushState) {

}
like image 62
Stefano Ortisi Avatar answered Oct 15 '22 02:10

Stefano Ortisi


The easiest (and most performant):

if ('history' in window && 'pushState' in history) { // available

Still, I'd suggest using some established solutions for history management, like History.js.

like image 24
raina77ow Avatar answered Oct 15 '22 01:10

raina77ow