如何禁用浏览器中的后退按钮?

时间:2016-10-09 07:41:54

标签: javascript php html5

我想在我的网页中禁用后退按钮..列出我可以执行此操作的方法... `

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

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

}   ?>`

3 个答案:

答案 0 :(得分:0)

也许这就是您正在寻找的答案:how to stop browser back button using javascript

如果是,下次请在询问前进行搜索;)

答案 1 :(得分:0)

以下是一些代码,除了IE9及以下版本之外,对我来说在所有浏览器上都有很好的效果。 (每次做pushState两次都是矫枉过正,但无论如何我都喜欢它。) 您只需要修改“myCritera,myStuff”等代码即可。

$(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({},'', '');
    }
});

答案 2 :(得分:-1)

这是我的代码,它运作良好:

 var url = window.history.forward();
 window.history.go(-window.history.length);
相关问题