-1

I want to disable back button in my webpage..list me the methods that i can do this... `

   if($data->num_rows > 0){
       while($row = $data->fetch_assoc()){

         header('Location:../cashier.php');
       }
   }else{
       echo "Username and  Password is Incorrect...Try  Again";
   }

} ?>`

Madhi
  • 45
  • 1
  • 12
  • The code you have posted has got nothing to do with back button and browser? – Sina Oct 09 '16 at 07:43
  • Possible duplicate of [how to stop browser back button using javascript](http://stackoverflow.com/questions/12381563/how-to-stop-browser-back-button-using-javascript) – Abela Oct 09 '16 at 07:46
  • I would say that is bad practice to alter the expected behaviour of the browser. You'd be better served with an exit popup. – ArtisticPhoenix Oct 09 '16 at 07:46

2 Answers2

0

Here is a bit of code that has worked wonderfully for me on all browsers except IE9 and below. (Doing the pushState twice each time is overkill, but I like it anyway.) You just need to modify the code that says "myCritera, myStuff" and the like.

$(document).ready(function() {
    if (myCriteria == 'yes') {
        window.addEventListener('popstate', function(event) {
            if (event.state) {
                if (window.history.state == null){
                    return;
                }
                $('#myStuff').hide();
                $('#myStuff2').hide();
                $('#otherStuff').show();
                window.history.pushState({},'', '');
                window.history.pushState({},'', '');
            }
        }, false);

        window.history.pushState({},'', '');
        window.history.pushState({},'', '');
    }
});
  • IE 11 has some weird quirks. Recently had to revise code to use: window.history.pushState({},'', window.location.href); – user7475459 Feb 08 '17 at 18:22
-1

Here's my code which works good:

 var url = window.history.forward();
 window.history.go(-window.history.length);
Aurasphere
  • 3,841
  • 12
  • 44
  • 71
Poornachander K
  • 603
  • 5
  • 4