Trying to make a single page application using window.onpopstate

61 views Asked by At

I have something like a single page web application. To handle a back button click from the user I use the 'popstate' event

Here it is:

window.addEventListener('popstate', function () { 
      
   backOneStep(0); // do my own job (get user to previous application screen)
   history.pushState(null, null, '');

});

In Firefox and Safari, the event works fine. When the user presses the "back" button - backOneStep is executed

For a long time everything was fine, but! But in Chrome, after the latest updates, the popstate event is not firing if the previous history.pushState call was initiated from code

So: If you press the back button once, you will find yourself one screen of the application back.

If you press the button a second time, you will be kicked out of my application :(

What confusing me - if you click anywhere on the page before the second click, the event will fire a second time too

I made simple example - https://w.ip.cv.ua/popstate.html

0

There are 0 answers