Yaron Ohana
Yaron Ohana

Reputation: 178

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.

Upvotes: 3

Views: 1586

Answers (3)

Yaron Ohana
Yaron Ohana

Reputation: 178

I just used windows.location.replace(newUrl) and it removed the page from the history and fix it.

Upvotes: 3

kiran
kiran

Reputation: 305

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
%>

Upvotes: -2

David Hellsing
David Hellsing

Reputation: 108520

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 = '/';
}

Upvotes: 0

Related Questions