back button link

Posted on 2006-03-28
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 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
    LVL 2

    Expert Comment

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

    Accepted Solution

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    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.
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now