通过单击浏览器的前进和后退按钮来阻止用户打开页面 [英] Prevent user to open the page by clicking back and forward button of the browser

查看:66
本文介绍了通过单击浏览器的前进和后退按钮来阻止用户打开页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我发现许多解决方案可以阻止浏览器上的后退按钮.例如window.history.forward()在返回的情况下可以正常工作.但是我的情况是这样的.

例如,我有2个表格A和B.现在,如果用户在页面A上,则单击链接转到页面B.在这里,用户可以单击并返回页面A.我对此没有任何问题.现在,我可以通过window.history.forward()阻止用户使用后退"按钮返回到页面B,它可以正常工作,但是我不希望用户使用前进"按钮来返回到页面B.我该如何预防呢?

希望我的问题清楚.

在此先感谢您.

Hello all,

I have found many solution to block back button on browser. For example window.history.forward() works fine in case of back. But my situation is something like this.

I have 2 forms A and B for example. Now if user is on page A, he clicks the link and goes to page B. From here user can click back and come back on page A.I don''t have any problem with that. Now I can prevent user to go back to page B with back button by window.history.forward(), it works fine but I don''t want user to go to Page B with Forward button. How can I prevent that?

Hope my question is clear.

Thanks in advance.

推荐答案

我看到了您的问题
我不知道如何在ASP中做到这一点.我是在PHP中完成此操作的,所以我要做的是检查会话内容.我开发了一个网站,用户可在该网站上登录,以便在单击后页或前进时使用它来保留用户名,然后再使用...来检查该会话是否仍保留用户名.如果是这样,则让他转到上一页或下一页,否则dnt允许使用转到上一页或下一页.在ASP中,您的问题仅适用于2种形式,因此您不能那样检查..u必须检查会话,或者必须使用Fwd按钮进行一些检查以限制用户进入B页.
希望您能得到答案
Hi i saw your question
i dnt know how to do that in ASP. I did this in PHP so what i did was i check the things with session. I developed web site where user use to log in so i use to keep the username in session, when use use to click the back page or forward...then i use check for whether that session still hold the username or not. If so then let him go to forward or back page else dnt let the use go to back or fwd page. In ASP ur question is just for 2 forms so for that u cant check like that..u will have to check for session or u have to put some check for restricting user to come to page B using Fwd button.
Hope u got your answer


please take a logout page and paste the following code in load event.
protected void Page_Load(object sender, EventArgs e)
       {
           try
           {
               FormsAuthentication.SignOut();
               Session.RemoveAll();
               Session.Abandon();


               //Added By Amin Uddin
               //Used To Protect Back button
               Response.Buffer = true;
               Response.ExpiresAbsolute = DateTime.Now.AddDays(-15);
               Response.Expires = -1500;
               Response.CacheControl = "no-cache";
               Response.Cache.SetNoStore();

               System.Web.HttpCookie cook = Request.Cookies.Get(Common.CommonCookie.cookName.userCook.ToString());
               cook.Expires.AddMilliseconds(1);

               string[] cookies = Request.Cookies.AllKeys;
               foreach (string cookie in cookies)
               {
                   Response.Cookies[cookie].Expires = DateTime.Now.AddDays(-1);
               }


           }
           catch  {
               FormsAuthentication.RedirectToLoginPage();

           }
           finally
           {
               FormsAuthentication.RedirectToLoginPage();
           }
       }



在loagin页面中写以下jscript


and
write the following jscript in loagin page

<script language="javascript" type="text/javascript">

      window.history.forward(1);

  </script>
  <script language="javascript" type="text/javascript">
      function disableBackButton() {
          window.history.forward();
      }
      setTimeout("disableBackButton()", 0);
  </script>


这篇关于通过单击浏览器的前进和后退按钮来阻止用户打开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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