Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: "Back" button

  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 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!
    Beck

  • #2
    New Coder
    Join Date
    Jan 2004
    Location
    Minnesota
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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()
    {
    history.go(-1);
    }
    </script>

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


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

    -meeka007

  • #3
    Regular Coder oldcrazylegs's Avatar
    Join Date
    Feb 2004
    Location
    East Moline Illinois USA
    Posts
    414
    Thanks
    4
    Thanked 5 Times in 4 Posts

    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>

  • #4
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Why clutter up the code with things that aren't needed. Here's the short version:

    <span onclick="history.back();">Back</span>
    Stephen
    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
    New Coder
    Join Date
    Jan 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •