Back Button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Back Button

Post by snicolas »

Hi guys,

How to create a Back button that will be placed in a form and return to the referer page, without resubnitting values etc...
I tried javascript:history.back(), but it soesn't work.

thx

s
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

javascript:history.go(-1)
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

yes, thank you i tried this, but in Mozilla, the (-1) does not redirect to previous page.
If you test this in Firefox, for example, you'll need to do a (-2) to return to correct page.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

snicolas wrote:yes, thank you i tried this, but in Mozilla, the (-1) does not redirect to previous page.
If you test this in Firefox, for example, you'll need to do a (-2) to return to correct page.
I have tested it in FF 1.0 and it works for me. Here is complete html doc:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY>
<form action='' method='GET'>
  <input type='button' name='back' value='Back' onClick='javascript:history.go(-1)'>
</BODY>
</HTML>
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

In my example, i found that:

<input type="button" value="BACK" name='back' onClick="javascript:self.location='<?php echo $_SERVER['HTTP_REFERER']?>'">

was a better solution.

s
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Yes that works too. And of course it will be completely browser independent since it is parsed in the server
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

d11wtq wrote:Yes that works too. And of course it will be completely browser independent since it is parsed in the server
It will be browser dependent because some browsers do not send the referrer URL :D
Post Reply