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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.