如何查找用户是单击浏览器后退按钮还是“刷新”按钮 [英] How to find whether the user clicks browser back button or Refresh button

查看:92
本文介绍了如何查找用户是单击浏览器后退按钮还是“刷新”按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要查看用户是单击浏览器后退按钮还是刷新按钮。

I need to find whether the user clicking the browser back button or Refresh button.

我需要在点击后面或刷新时将页面重定向到错误页面按钮。怎么做。

I need to redirect the page to Error page when he clicks the back or refresh button. How to do this.

我需要在我的ASP.net页面的javascript中这样做

I need to do this in javascript for my ASP.net page

推荐答案

首先,如果用户使用Back或者因任何原因必须刷新页面,给出错误消息是一个非常糟糕的主意。相反,你应该透明地处理它。考虑到由于运输级别的问题而导致页面无法完全显示 - 用户唯一的选择是重新加载或返回。

First of all, giving error messages if users use Back or have to refresh a page for whatever reason, is a really bad idea. Instead, you should transparently deal with that. Think about a page not coming up fully because of problems on the transportation level - the only option the user has is to reload or go back.

要回答您的问题,请必须自己跟踪用户的导航,这意味着在服务器端。在这里忘记java脚本。如果用户访问网站,您可以将该信息存储在与用户关联的会话中(有几种方法可以保留这些唯一会话,我不会在此处详细介绍)。
如果您在内部结构中存储了用户最近访问过的页面,则很容易确定两次访问的页面,或导航进入错误的方向。

To answer your question, you have to keep track of the user's navigation yourself, that means on the server side. Forget about java-script here. If the user visits a website, you can store that information in a Session associated to the user (there are several methods of keeping these unique sessions, and I won't go into details here). If you store in your internal structures which pages the user visited lately, it is easy to determine a page being visited twice, or navigation going into the "wrong" direction.

您可以轻松地概括这一点(并使整个事物更加健壮,例如针对用户在网址之间疯狂跳跃,或者一次性返回多个步骤),方法是构建一个允许导航图并遍历它用户正在访问网站。

You could easily generalize this (and making the whole thing more robust, for example against users jumping wildly between urls, or going back more than one step at once) by building a graph of "allowed" navigation and traversing it while the user is visiting websites.

如果用户正在进行错误导航(如退回,重新加载==访问两次),那么正确的行为就是让他回到正轨。不要给出他无法逃避的错误信息!由于他不被允许重装或回去,他没有选择权。

The correct behaviour then if the user is doing a "wrong" navigation (like stepping back, reloading == visiting twice) is to get him back on track. Not to give an error message he can't escape! As he is not allowed to reload or go back, he has no options left.

这篇关于如何查找用户是单击浏览器后退按钮还是“刷新”按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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