A user over at Experts Exchange was looking for a way to create an Exit button of sorts that would return the user to the page that referred them to the site (i.e. if the user got to the page via Google, the link would return them to Google).
If the goal was to simply navigate back one page to return the user, the following code could be used simply to go back one page in the browser history:
However, if the goal is to let the user navigate to different pages throughout the site (say two or three clicks into the site) and then return to the referring site, it can be a little more complicated. This can be solved with some simple jQuery, here is a simple example:
In this example, I am using the jQuery cookie plugin found here. When the page first loads, it checks to see if a cookie already exists for the referring URL, if not it sets it. Then, when the link (or button or image) calls the ExitURL() function with the onclick, the cookie is read, deleted, and then the user is redirected back to the referring URL.
Pretty simple. Ask you have any questions :D