0

I am using history.pushstate method to add the history into the browser and added the history as follows in the browser.

       history.pushState("", "",myurl);

The history added in the browser correctly.(When the browser history clicked the correct page getting loaded.)

But when i click the back button in the browser it doesn't go back..

(i.e I am using hashchange functionality to show different contents in the page).

Actually it requires another click to go back.(i.e two clicks of back button to go back to the previous page added in the history).

How can i make it to back in only one click of back button.

Aravindhan
  • 3,430
  • 7
  • 23
  • 40
  • Here's an SO question for a tutorial using HTML5 History: [Good tutorial for using HTML5 History API (Pushstate?)](http://stackoverflow.com/questions/4015613/good-tutorial-for-using-html5-history-api-pushstate). As the answer mentions, you should consider using [`History.js`](https://github.com/balupton/History.js). – kevinji Mar 04 '13 at 05:37

2 Answers2

0

Don't use hashchange for history; that's only for the fragment changing. Use popstate.

window.addEventListener('popstate', function () {

});

http://jsfiddle.net/ExplosionPIlls/NkEdg/

Explosion Pills
  • 176,581
  • 46
  • 285
  • 363
0

I found a working solution as follows.

Using replacestate instead of pushstate solved the problem.

Pushstate add the history but it doesn't points the top of the stack.So at first click the same page from history loaded and in the next click the previous page get loaded.

Aravindhan
  • 3,430
  • 7
  • 23
  • 40