0

I am facing issue while calling the browser back button. Actually in home page I am displaying the bootstrap modal for signup. But when user clicks on another page like cart page... once user reaches the cart page and presses browser back button modal again shows. I want to hide the bootstrap modal on browser back button. I have tried many snippets but none is working. Below is my code:-

$(function() {
  if (window.history && window.history.pushState) {
    $(window).on('popstate', function() {
      alert('Back button was pressed.');
      $('#MyMODAL').modal('hide');
    });
  }
});

Not even the alert box is showing. Can anyone help me on this issue.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • I believe popstate is not triggered or available in page load. I would use a sessionStorage var – mplungjan Oct 03 '20 at 05:59
  • Does this answer your question? [JavaScript or jQuery browser back button click detector](https://stackoverflow.com/questions/17594413/javascript-or-jquery-browser-back-button-click-detector) – Asaf Oct 03 '20 at 07:17

0 Answers0