This question already has answers here:
Disable browser's back button
                                
                                    (20个答案)
                                
                        
                                5年前关闭。
            
                    
登录页面出现时,我有一项禁用后退按钮的要求。

注意以下代码不起作用。

function DisableBackButton() {
    window.history.go();
}

window.onbeforeunload = DisableBackButton;


对于服务器端,我还添加了一些服务器端代码,如下所示。

response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);%>

最佳答案

尝试这个:

window.onload = function () { history.forward(); }; //force user to redirect
window.onunload = function() {}; // trick for some browsers like IE

09-25 20:30