如何在ASP.NET中阻止用户/禁用浏览器返回事件 [英] How prevent user/disable browser back event in ASP.NET

查看:56
本文介绍了如何在ASP.NET中阻止用户/禁用浏览器返回事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net C#。我创建了一个内容页面。我不希望用户使用浏览器返回按钮返回。我发现可以使用javascript完成.Below是我的代码。< br $> b $ b

< script>

函数preventBack(){window.history.forward();}

setTimeout (preventBack(),0);

window.onunload = function(){null};

< / script>

但我使用的内容页面不是正常的网页。我的页面没有正文标签。我想只为这个页面而不是整个网站禁用后退按钮。怎么做?



我尝试过:



javascript代码:



< script>

函数preventBack(){window.history.forward();}

setTimeout(preventBack(),0);

window.onunload = function(){null};

< / script>

I am using asp.net C#.I have created one content page.I don't want user to go back using browser back button.I came to know that it can be done using javascript.Below is my code.

<script>
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
window.onunload=function(){null};
</script>
But I am using content page not normal webpage.My page don't have body tag.I want to disable back button only for this page not entire web site.How to do that?

What I have tried:

javascript code :

<script>
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
window.onunload=function(){null};
</script>

推荐答案

你不能禁用后退按钮或后退功能。



你不应该花时间去做的事情。 ASP.NET论坛 [ ^ ]



过去20年来人们一直在问这个问题,答案仍然是一样的,请在发布之前做一些基本的研究,比如使用google。
You can't disable the back button or back functionality.

Things you shouldn&#39;t spend time doing | The ASP.NET Forums[^]

People have been asking this question for the last 20 years and the answer is still the same, please do some basic research like use google before you post.


这篇关于如何在ASP.NET中阻止用户/禁用浏览器返回事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆