0

I want to call a function on back button click, I am using the below code which is working on both forward and back button but I want only back button click. Not be able to differentiate between Back and Forward click.

if (window.history && window.history.pushState) {

    window.history.pushState('forward', null, './#forward');

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

  }
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Shlok Thakur
  • 13
  • 1
  • 7
  • [This answer](https://stackoverflow.com/questions/25806608/how-to-detect-browser-back-button-event-cross-browser) has some useful tips. Take a look. – lshettyl Oct 07 '17 at 11:27
  • Not working mention solution in attached link. Methods all are working in both forward and back click. – Shlok Thakur Oct 07 '17 at 13:12

0 Answers0