简体   繁体   English

按下后退按钮上的重定向页面

[英]Ignore redirect page on press back button

I have a "loading page" to indicate the users that the system is searching. 我有一个“加载页面”来指示系统正在搜索的用户。 I want to skip this page when user press back button and redirct him to the first page. 当用户按下后退按钮并将他重新定位到第一页时,我想跳过此页面。

How to do that? 怎么做? Thanks. 谢谢。

我刚刚使用了windows.location.replace(newUrl) ,它从历史记录中删除了页面并修复了它。

You can check the referrer and match on the loading page. 您可以检查引荐来源并在加载页面上进行匹配。 If the referrer is the page that was the page "after" the loading page, you can assume that the user pressed back. 如果引荐来源是加载页面“之后”页面的页面,则可以假定用户已按下该页面。

You can do this on the server or in javascript, example (pseudo) in JS: 您可以在服务器上或javascript中执行此操作,JS中的示例(伪):

if ( document.referrer.test(/[URL]/) ) {
    window.location = '/';
}

Using javascript 使用javascript

Response.Cache.SetNoStore(); Response.Cache.SetNoStore(); or window.history.forward(1); 或window.history.forward(1);

This will disable to back button functionality. 这将禁用后退按钮功能。 also maintian some session value which will be set to empty in case of back button click. 还有一些会话值,如果单击后退按钮,将设置为空。 like below one. 喜欢下面的一个。

<%
  Response.Buffer = True
  Response.ExpiresAbsolute = Now() - 1
  Response.Expires = 0
  Response.CacheControl = "no-cache"

  If Len(Session("FirstTimeToPage")) > 0 then
    'The user has come back to this page after having visited
    'it... wipe out the session variable and redirect them back
    'to the login page
    Session("FirstTimeToPage") = ""
    Response.Redirect "/Bar.asp"
    Response.End
  End If
%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM