如何禁用浏览器的后退或前进按钮 [英] how to disable back or forward button of a browser

查看:430
本文介绍了如何禁用浏览器的后退或前进按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个网站,其中第一页是登录页面,第二页是主页.首先我通过登录进入主页.现在,如果我单击浏览器的后退按钮登录页面.问题是,如果我单击浏览器的前进按钮,则会加载主页.我想禁用前进按钮,以便在没有
的情况下无法打开主页 登录.请提供代码解决方案.

I have created a website in which first page is log in page and second page is home page.At first I enter into the home page by logging.Now if I click browser''s back button log in page is loaded.Problem is that,if I click browser''s forward button the home page is loaded.I want to disable the forward button such that the home page is not opened without
log in.Please give a solution with code.

推荐答案

在Page_Load事件之前粘贴此代码

Paste this code just before Page_Load event

报价:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();



在那之后,一旦您通过销毁会话离开Home Page,您将无法返回Home Page,除非并且直到您登录

如有任何疑问,请回复我.

谢谢和问候
苏曼·扎洛迪亚(Suman Zalodiya).



After that once you will leave Home Page by destroying session, you won''t be able to go back to Home Page unless and until you log in

Please revert back to me in case of any doubts.

Thanks and regards
Suman Zalodiya.


我觉得你的做法不对.

为此,您必须处理会话.成功验证用户登录名后.您必须创建一个会话,以便该会话对于用户而言仍然有效.当用户要从应用程序注销时,会话将关闭.

因此,如果有任何用户直接访问主页.会话值为null.这样您就可以重定向到登录页面.

我认为这对您有帮助.
I feel that you are going in wrong way.

for this you have to work with sessions. When the user login is validated successfully. you have to create a session, so that the session will be alive for the user. when the user want to go for log-out from the application the session will be closed.

So if any user access the home page directly. the session value is null. so that you can redirect to login page.

I think this is helpful to you.


我为您的查询提供了答案

这是通过javascript完成的.将以下脚本剪切到您要禁用IE后退按钮的页面中

< script language ="JavaScript">
javascript:window.history.forward(1);
</script>


希望对您有帮助!
I hav an answer for your query

It is done by javascript. Cut the below script into your page where u want to disable the back button of IE

<script language="JavaScript">
javascript:window.history.forward(1);
</script>


hope this will help u!


这篇关于如何禁用浏览器的后退或前进按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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