Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find if a browser supports History.Pushstate or not?

I want to change URL without without reloading the page. The possible solution I found is

window.history.pushState('page2', 'Title', '/page2.php');

but some browser like Firefox 3.5, IE6+ does not support this, so for them solution is

var uri = window.location.href;

but the issue is how to discover if a browser supports history.pushstate or not?

Is TRY CATCH is the possible solution or any thing else.

like image 926
Ashish Agarwal Avatar asked Jul 26 '11 03:07

Ashish Agarwal


People also ask

What is history pushState?

In an HTML document, the history. pushState() method adds an entry to the browser's session history stack.

How do I check my browser history stack?

history object allows you to access the history stack of the browser. To navigate to a URL in the history, you use the back() , forward() , and go() methods. The history. length returns the number of URLs in the history stack.

Does history pushState reload page?

But this function is not intended to reload the browser. All the function does, is to add (push) a new "state" onto the browser history, so that in future, the user will be able to return to this state that the web-page is now in.


1 Answers

if (history.pushState) {   // supported. } 

Quickest test is to run this in the browser console to see if it's supported:

if (history.pushState) { alert('supported'); } 

Also notice that in FF typeof(history.pushState) returns "function", while in IE it returns "undefined"

like image 130
Kon Avatar answered Sep 22 '22 06:09

Kon