[Webinar] Learn how to a build a cloud-first strategyRegister Now


back button link

Posted on 2006-03-28
Medium Priority
Last Modified: 2010-08-05
I wanted to add a link to my site on each page so people can go back.

Is there an easy way to do this?

If someone went through 5 pages, and they hit the link I am going to make, how will I know to go through the 5 pages?

I don't want it to just go to the referrer.

If they go from page 1 to page 2 ...page 5 then hit back it should go to page 4, if from there they hit the back button, it should go to the previous one from page 4, which was page 3, not just back to page 5.
Question by:jackjohnson44

Expert Comment

ID: 16311448
Try using this  in your back link and change the -1 to -5 or whatever depending on the amount of pages you want to go back:

<a href="Javascript:history.go(-1)">Back</a>

Accepted Solution

noamattd earned 2000 total points
ID: 16321871
If you want to go back 1 page, use

<a href="javascript:history.back();">Go back</a>
or <a href="javascript:history.go(-1);">Go back</a>

for your link.  You may also want to consider having "forward" links as well, and for those, you would use

<a href="javascript:history.forward();">Forward</a>
or <a href="javascript:history.go(1);">Forward</a>

I may have misinterpereted you but it sounds like you want to go all the way to the first page in the history as well?  For that just use
<a href="javascript:history.go(-(history.length));>Go to the beginning</a>

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question