Web Analytics Made Easy -
StatCounter "Back" button - CodingForum


No announcement yet.

"Back" button

  • Filter
  • Time
  • Show
Clear All
new posts

  • "Back" button

    Could someone please tell me what code I need to use to create a "back" button link (same function as a browser back button)?
    Thanks very much!

  • #2
    I ran across it here in the forum but I can't remember where it is so here's the code that I use.

    <script type="text/javascript">
    // Return to the previous page
    function GoBack()

    <input type="reset" value="BACK" onClick="GoBack()">

    You can just change the number in the history.go(#) to go back more than one page.



    • #3
      Back button

      Here is an easier way.

      Back Button
      <a href="javascript:void(0)" onclick="javascript:history.go(-1);">Back</a>

      Forward Button
      <a href="javascript:void(0)" onclick="javascript:history.go(+1);">Forward</a>
      Master Newbie http://dwightstegall.com/


      • #4
        Can I just say a 'BIG THANKS" to OLDCRAZYLEGS.....

        I have been trying to get firefox 2.0 to respond to javascript "BACK" button, for 1/2 a day now.
        All solutions worked fine in IE7...but none worked in FF2.0.
        The screen would momentarily flicker back to the previous page, and then land back on the one that made the call.

        I used 'window.location = history.go(-1);'
        .... and placed this within a function in the head of the page (returnto lastpage(), and called that function from the html doc via the <a href="#" onclick = "returntolastpage();"> pic to click </a> method.
        This worked fine in IE, but not in FF. I tried all manner of permatations, but with the same result.

        However this embedded 'inline' method of OLDCRAZYLEGS works in both browsers, and has saved me some grief! .... many thanks guys.


        • #5
          Why clutter up the code with things that aren't needed. Here's the short version:

          <span onclick="history.back();">Back</span>
          Learn Modern JavaScript - http://javascriptexample.net/
          Helping others to solve their computer problem at http://www.felgall.com/

          Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


          • #6
            First I am not a programmer. I just found these scripts elsewhere. It seems to me the easiest way is.......

            For back button I use: history.go(-1)

            For forward button I use: history.go(+1)

            I simply do not understand for example:
            <a href="javascript:void(0)" onclick="javascript:history.go(+1);">Forward</a>

            For that matter, neither does Avant browser (which is what I am putting scripts like the ones I listed into). Whenever I post requests for help and I get a response with two segments (script and body) I never know how to add the body portion so that Avant recognizes it.

            Anyway, as I originally stated, the two listed above seem simplest and shortest.