0

How we can detect the browser back button click (for any type of browsers)?

My Browser Url : http://project_name/razorpay/pay.php?checkout=manual&invoice=80

I try below code in pay.php page but not getting any alert or console data :

1.
window.onhashchange = function() {
  console.log('call');
}

2.
$(window).on('popstate', function (e) {
    var state = e.originalEvent.state;
    if (state !== null) {
        console.log('call');
    }
});
  • I want to call Cancel Order API on browser button click without successfully payment – Manish Patel Nov 19 '20 at 10:40
  • You can't reliably do this. You can only detect when a page has been unloaded, not ***how*** it was caused to be unloaded. There are some workarounds, as detailed in the duplicate I marked, but they are very easily broken and cannot be guaranteed to work in all situations on all devices. – Rory McCrossan Nov 19 '20 at 10:41

0 Answers0