Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing user from going back to previous page.

Status
Not open for further replies.

gust1480

Programmer
Mar 19, 2002
148
PH
How can i prevent user from going back to some pages they have already been to...
ex. Page1 -> Page2 -> Page3

Once on page3 user won't be allowed to go back to page 2.

Please help! thanks in advance!
 
here are the options..select one...

put this in the head tags
Code:
<script language="javascript">
     window.history.forward(1);
</script>

or
Code:
<body onLoad="history.go(+1)">

or

Code:
<script>
function KeyCache() {
  if (window.event && window.event.keyCode == 8) {
    window.event.keyCode = 123; //Replaces with F12 button. (Does nothing in IE)
  }
}
document.onkeydown=KeyCache();
</script>

-DNG
 


Look into Cache control to ensure the page expires immediately (and the browser/proxy doesn't cache it).

Then track the progress in a session variable, and ensure the user is always directed to the correct position they need to be...e.g.:

Page1.asp - Old Page
Page2.asp - Old Page
Page3.asp - Current Page
Page4.asp - Not yet seen

Session("MultiStepFormPagePosition") = 3

on each page check current page index against the session variable, and response.redirect them to the correct page if they're not already there.

This should stop users in the same session from either seeing a cached previous page by hitting their back button or by requesting a new page (e.g. typing the previous pages url in again).

You might want to ensure that the final page clears the session variable, so they can go through the process again (if that's what you want).

If you only EVER want users to visit a page once (weird requirement, but you never know - and your request is a little vague) then you will need to keep a history of the visited pages in a persistent data store of some sort. If it is just for that session, then you can again use the session variable to keep a history of pages.

Hope that helps,

A smile is worth a thousand kind words. So smile, it's easy! :)
 

DNG,

With options 1 and 2, if the user was to select the second from last (i.e. 2 pages ago) from the back button dropdown, then they would get the previous page, not the latest page.

Option 3 has so many potential issues I won't even comment.

Besides, they all rely on Javascript - which not all users will have enabled.



A smile is worth a thousand kind words. So smile, it's easy! :)
 
Set a session variable for the current page name at the end of the ASP processing. At the beginning of the script, check to see what the page name is against an array of page names, and if the page name isn't the previous one in the array, redirect to the next one in the array. This can be an INCLUDE file so any changes made only need to be done in one file. Something like this:
Code:
Dim pagenames, thispage, pageindex

pagenames = new Array("page1.asp", "page2.asp", "page3.asp", "page4.asp")

'thispage = get this page URL from server variables

pageindex = 0
While pagenames(pageindex) <> Session("pagename")
  pageindex = pageindex + 1
Wend

If thispage <> pagenames(pageindex + 1) Then
  Response.Redirect pagenames(pageindex + 1)
End If

Session("pagename") = thispage

'rest of page

Lee
 
A1ien51's disable the Back Button
What is going to happen, is when the page loads, it will send the surfer to the last page in their history.
Now if a person tries to go back to it, then it will send them directly back to the page they pushed the back button on!
Add this code to the header of your page:
<script>
history.forward();
</script>

JPS: Thus need to put the code on the page you don't want the user to be able to go back to.
And here is my version of it:
<script type="text/javascript"> <!--
// Disable browser's Back button on another pg being able to go back to this pg.
history.forward();
//-->
</script>

Best regards,
-Paul
- Freelance Web and Database Developer
- Classic ASP Design Tips
 

Bullschmidt,

That's effectively the same as DNG's post, which I've commented on above. There are several ways around this - even accidentally.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top