简体   繁体   中英

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:

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

Using javascript

Response.Cache.SetNoStore(); or 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
%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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