zeckdude
zeckdude

Reputation: 16163

How can I create a back button that takes you back to the page you came from?

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?

Upvotes: 1

Views: 331

Answers (4)

Merle_the_Pearl
Merle_the_Pearl

Reputation: 1521

Also - if u just want an

 <a href="javascript:go(-1)" class="dbutton" onClick="history.back()">Back</a> 

Upvotes: 0

agentile
agentile

Reputation: 252

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>

Upvotes: 2

Kugel
Kugel

Reputation: 19824

<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>

Upvotes: 3

Brandon Henry
Brandon Henry

Reputation: 3720

problem with

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

?

Upvotes: 10

Related Questions