简体   繁体   English

禁用浏览器后退按钮,但在我的asp.net应用程序中保持启用状态

[英]disable browsers back button but keep it enable within my asp.net application

I have searched and implemented a code where I am able to disable the back button of the browser. 我已经搜索并实现了一个代码,可以在其中禁用浏览器的后退按钮。 But I am facing a problem like when I log in and don't do anything and click back button it takes me to login page and then a forward button appears. 但是我遇到了一个问题,例如当我登录并且不执行任何操作并单击“后退”按钮时,需要我进入登录页面,然后出现“前进”按钮。 I don't want the back button to get functional on my home screen immediately when I am logged in. But the back button should be enable within my application but not exactly after i log in. Following is my code that I have used in my master page coding. 我不希望后退按钮在登录后立即在主屏幕上起作用。但是后退按钮应在我的应用程序中启用,而不是在登录后立即启用。以下是我在我的代码中使用的代码母版页编码。 Please help as I am working on live application. 我正在开发实时应用程序,请提供帮助。

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

</script>

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

On code behind(Server side) write this: 在后面的代码(服务器端)上编写以下代码:

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();


   }

and on client side write this: 在客户端写这样的:

<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>

Lot's of way's here 很多方式在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM