Monday, February 29, 2016

Disable Back Button using Javascript




User tries to use back button for most of the applications and it is valid, but few of the cases is required to disable the back button and also restrict the user.

It would be very useful when the user is on payment page. Below is the code to disable the back button in Browser.

var currentURL = window.location.pathname + window.location.search;
 history.pushState(null, null, currentURL);
 window.addEventListener('popstate', function(event) {
  history.pushState(null, null, currentURL);
 });

It works in all major browsers

No comments: