How to trigger change when using the back button with history.pushstate and popstate?

The popstate only contains a state when there is one.

The popstate only contains a state when there is one. When it goes like this: initial page loaded new page loaded, with state added via pushState back button pressed then there is no state, because the initial page was loaded regularly, not with pushState. As a result, the onpopstate event is fired with a state of null.So when it is null, it means the original page should be loaded.

You could implement it such that history. PushState will be called consistently and you only need to provide a state change function like this: jsfiddle.net/SNsnN/5/.Function change(state) { if(state === null) { // initial page $("div"). Text("Original"); } else { // page added with pushState $("div").

Text(state. Url); } } $(window). Bind("popstate", function(e) { change(e.originalEvent.

State); }); $("a"). Click(function(e) { e.preventDefault(); history. PushState({ url: "/page2" }, "/page2", "page 2"); }); (function(original) { // overwrite history.

PushState so that it also calls // the change function when called history. PushState = function(state) { change(state); return original. Apply(this, arguments); }; })(history.

PushState).

Thank you very much for you help @pimvdb and even more so, for the super quick reply. All the best. – Ross Wilson Nov 7 at 16:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions