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

Forcing a refresh on back button

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
If I understand the back button correctly, it does not, by default, refresh the previous page. How do I force a refresh on a particular page if it is accessed via the back button?

Thanks.
 
From some of the posts I've read here, I don't think there's anyway to capture the event of clicking the back button.

If your page is in a javaScript-spawned window without the standard tool bar, you could provide your own "back" button that would enable you to insure that the previous page is being refreshed, since you could be able to act on the clicking of that button. But even that is not foolproof since you can right-click and then select "back."

You might give us some information about the page you want refreshed, and why. Perhaps there's some suggestions we could make that might give you the results you're looking for. I'm guessing it's a form...

Good luck.
 
ASP? if the page in question is using post info (from a form, say) the browser (IE for sure) wont let the user see it with out refreshing.
 
you can set the no-cache value to the pages
<META HTTP-EQUIV=&quot;expires&quot; CONTENT=&quot;0&quot;>
<meta http-equiv=&quot;Cache-Control&quot; content=&quot;no-cache&quot;>

_________________________________________________________
$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;

onpnt2.gif
[/sub]
 
Thanks to all that replied.

onpnt:
That didn't seem to do anything.

greedyzebra & theocraticmind:
Perhaps this is a PHP question then. I have a PHP script that generates a form which presents the user with some file names. The user makes action selections on those file names then submits the form (POST). The second execution does things with the files that makes the first pass obsolete. Indeed, if the user hits the back button then submits again, undesirable results can occur. I want the first pass form to either automatically refresh or become expired and not displayed. I can my own back button on the second pass but that does not prevent the user from hitting the browser back form.
 
I know with ASP and IE pages &quot;expire&quot;. that is, the user must refresh the page (and resubmit and post info) if the page was using post info. My guess is that this would be the same for PHP and any (most) borwser(s). So, maybe you could use some post info in teh first page... just a dummy value to force reload. I don't use PHP though, so I don't know how you could do it.
 
Hi,

Try adding the following PHP code to the top of the page.

if($HTTP_REFFERER!=$PHP_SELF){
header(&quot;Location: $PHP_SELF&quot;);
}

or add <META HTTP-EQUIV=&quot;Pragma&quot; CONTENT=&quot;no-cache&quot;> in your header tags.
 
Just to close this out, Someone on the javascript forum suggested a cool solution that effectively disables the back button.
Code:
.
.
.
<head>
<script language=&quot;javascript&quot;>
   window.history.go(+1);
</script>
.
.
.
</head>
.
.
.
The first time the page displays the '+1' does nothing because there is no forward page yet. When the submit button of the form is clicked and the page redisplayed (creating a forward page with respect to the previous one), clicking on the back button causes the first page to immediately redisplay the second. In effect the back button does nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top