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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does my previous expire?

Status
Not open for further replies.

MichaelLewis

Programmer
Feb 5, 2011
12
FR
To go back to my previous web page, I issue the following:

function goBack()
{window.history.go(-1)}

but then I'm told my web page has expired.

Why is this? How do I correct so it doesn't expire?

Thanks,
Michael
 
I ran into this a while ago and it seems to depend on whether there was a POST, from a <form> or language (eg. PHP), on the previous page. They tend to "expire". Although, one might expect that annoying popup asking "do you want to submit your post?" to appear.

You can go back further; history.go(-3) 'three pages. Just a thought.

-Geates

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
I tried the -3 but it doesn't work. I get the same result. The previous page is simply not there.

However, you seem to be correct that it has something to do with the POST. If I turn off the post, it works, but then I can't get the data from the form (or is there another way I can pass on the data entered in the form?)
What I have is:
Page 1 = Form for the user to enter the year desired. Submit calls page 2 which needs the year.
Page 2 = Form to allow the user to enter more data (including the year entered on Page 1). Submit calls a programme to update the database and then return to Page 2, via window.history.go(-1),
for more data (again, including the year entered on Page 1).

So, if the problem is the POST, how do we get around that? Is it an HTML bug?

Thanks,
Michael

 
Is it an HTML bug
No, it's how HTTP works.

Submit calls a programme to update the database and then return to Page 2, via window.history.go(-1),
for more data (again, including the year entered on Page 1).
Send the user to the apprpriate page serverside NOT with javascript.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I agree. Instead of using histroy.go(-1), send the user to the second form and pass the year they selected from form 1. It should be stored in the $_POST variable (assuming you're using PHP).

Code:
<form action=\"form2.php?year=$_POST['my_year_var']\">

-Geates

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
My update of the database does not have a form. So rather than setting up a form, based on what you guys told me, I changed my goback funtion (intead of to -1) to the following and that works fine.

function goBack()
{location.href=\"DataEntryForm.php\";return false;
window.open(location.href); return false;}

For passing back the year, I used "$_SESSION['useryr']=$useryr;"

I don't know if this is the best way but it works!

Many thanks for your help,
Michael
 
that works. you could condense your goBack function down to just
Code:
window.open('DataEndtyForm.php');

-Geates

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
Or even better, you no longer need javascript for what you're doing:
Code:
<a href="DataEntryForm.php">Back</a>
If you're redirecting automatically, look into [tt]<meta http-equiv="refresh" content="2;url=DataEntryForm.php">[/tt], where the number represents seconds before the redirect.

[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top