0

popstate event does not get fired when clicking on the browser back button this is my code

$(document).ready(function() {
      if (window.history && window.history.pushState) {
        window.history.pushState('forward', null, './#forward');

        $(window).on('popstate', function() {
          alert('Back button was pressed.');
        });
      }
    });

When put this code in the console it works but when I put in the file and try to load the page and click on the back button nothing happens. It redirects me to the previous page no alert. I noticed if do not do anything on the screen then it does not work but if you click on scroll on the screen then the popstate event gets called

Jhon Cuit
  • 17
  • 4
  • Try using the browser's debugger tool. You can set breaks points, inspect the variable and such to see what's happening. – Paul T. Jan 16 '23 at 22:09
  • its related to this question. It will give more understanding of the senario: https://stackoverflow.com/questions/57339098/chrome-popstate-not-firing-on-back-button-if-no-user-interaction – Jhon Cuit Jan 23 '23 at 05:39

0 Answers0