View Full Version : Browser Back Button Control

07-13-2006, 12:48 PM
I need to control the back button - browser history, so when in page2, it goes back to page1, and when in page3 it goes back to page1. (Gotta avoid $_POST a second time in page2). The catch is that page two is not always in the sequence because of a cookie check.

I think it will be allright to make the browser history for page2 = page1 (falsifying the entry). How can I control the browser history?

I've been fighting this problem for almost month, thought it was other things for a while, learned a lot, but just never enough (yet).

~~~~ (new edit)

Just found some code on DD (a Marquee script discussion) that gave me a hint, so I'm now thinking, is this the right way to go? Will it work correctly in all browsers? How about even IE? I found a lot of garbled (to me) discussions of banned sites using this too?

function _begin_html()
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<link rel="STYLESHEET" type="text/css" href="lib/style.css">
<title>Password Login ver 0.0.2</title>
<script language="javascript1.1">
<script language="javascript">
window.location.href = "http://earth.ccny.cuny.edu/noaa/wc.html";

07-13-2006, 06:11 PM
I tried this out, and found that it does rewrite the history for the page it's in, AND (this is the part that doesn't work for me) immediately takes me to that page. So, history is rewritten AND simultaneously invoked.

Bad, is there any way around this?

07-14-2006, 04:33 PM
Browser history is protected from most manipulations. All you can do is prevent a page from being added to the stack and replace a page's position in the stack. But, if a user is navigating primarily with their back and forward buttons, or has javascript disabled, even these methods cannot be relied upon. I didn't look at all your code above because there really is no javascript solution to this. You will need a server side solution to the problem, probably one not using history but, rather a session variable or some such thing, server side is not my strong point though.

What kind of server side language are you using to process your form? Post your problem in the forum dedicated to that language. I'd suggest using that language to create a session variable that redirects away from the page you don't want loaded a second time if it has already been visited. Those more familiar with server side coding may have a better idea.