tags:

views:

77

answers:

3

I am trying to create a button that knows what page you came from and enters that value into the anchor tag. Does anyone know a solution using either jQuery or PHP or both?

+3  A: 
<FORM>
<INPUT TYPE="button" VALUE="Go Back" onClick="history.back()">
</FORM>

Also you can go back more pages, like this:

<FORM> <INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1)"> </FORM>
Kugel
not following standards.
thephpdeveloper
+9  A: 

problem with

<a href="javascript:go(-1)">back</a>

?

Brandon H
+2  A: 

In PHP, you could keep track of the last page the user was on by using

$_SERVER['REQUEST_URI'];

and storing it in the session.

$_SESSION['last_page'] = $_SERVER['REQUEST_URI'];

and run it after your html for the current page is rendered, then in a link you could have something like this

<a href="<?php echo $_SESSION['last_page']; ?>">Back</a>

agentile