我已经搜索并实现了一个代码,可以在其中禁用浏览器的后退按钮。但是我遇到了一个问题,例如当我登录并且不执行任何操作并单击“后退”按钮时,需要我进入登录页面,然后出现前进按钮。我不希望后退按钮在登录后立即在主屏幕上起作用。但是后退按钮应在我的应用程序中启用,而不是在登录后立即启用。以下是我在我的代码中使用的代码母版页编码。我正在开发实时应用程序,请提供帮助。

<script type="text/javascript">
        function disableBackButton() {
            window.history.forward(1);
            //alert("You cannot Nevigate To Back!!!");
        }

</script>

<body onload="disableBackButton()" >
</body>

最佳答案

在后面的代码(服务器端)上编写以下代码:

protected void Page_Load(object sender, EventArgs e)
   {

     HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
     HttpContext.Current.Response.Cache.SetNoServerCaching();
     HttpContext.Current.Response.Cache.SetNoStore();


   }


在客户端写这样的:

<script type="text/javascript" language="javascript">
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{
case 116 : // F5;
event.returnValue = false;
event.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
</script>


很多方式的here

10-06 07:35
查看更多