Consider this snippet:
console.log( "1st", history.length ); location.hash = location.hash + "some-value"; console.log( "2nd", history.length ); setTimeout( function() { console.log( "3rd", history.length ); history.back(); console.log( "4th", history.length ); }, 1000 );
https://jsfiddle.net/1kqLofq4/2/
I am wondering why changing the hash does not adjust the length of the history, but is using history.back () required to return to changing the hash? I tested this scenario with Firefox 46 and Chrome 49. The output is always similar to this:
1st 17 2nd 17 3rd 17 4th 17
I tried to find some specifications or information about this case, why it could be the intended behavior and how I could detect changes in the history, like this, using some other information than history.length. But all I got was a hint of using some fancy framework plugins that definitely don't interest me.
source share