Search code examples
history.js

Jquery browser history js - same action doesnt fire second time - no state change workaround


Using browserstate/history.js

All my links are running through the history adapter:

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

// do some stuff here

});

but if a user clicks the same link twice in a row then the second time it will not run since there is no 'statechange'. What is the solution for this?


Solution

  • You can add random data to differentiate the actions:

    History.replaceState( {randomData: window.Math.random()}, '', url);
    

    That way statechange will always fire.

    Found answer here https://github.com/browserstate/history.js/issues/293