Rollback javascript history

Is there a way to provide a hook like onHistoryBack? I am currently using history.js with

History.Adapter.bind (window, 'statechange', function () {});

But I have no way to ask if the user had presed history.back () or if he had called History.pushState () ... any idea?

+5
source share
2 answers

The way I did this was to set the value of the true variable for every click on the actual site. The statechange event will then check this variable. If true, they used the link on the site. If this was incorrect, they pressed the browser button back.

For instance:

var clicked = false;

$(document).on('click','a',function(){

    clicked = true;

    // Do something

});

History.Adapter.bind (window, 'statechange', function () {

    if( clicked ){
        // Normal link
    }else{
        // Back button
    }

    clicked = false;

});

Hope that helps :)

+2
source

History.savedStates. , , . History.savedStates, , History.savedStates[History.savedStates.length - 2] == currentState. , a, b, a. , "", .

History.getStateByIndex .

+1

All Articles