Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-11-2004, 01:37 PM   PM User | #1
Beck1
New Coder

 
Join Date: Aug 2002
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Beck1 is an unknown quantity at this point
"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
Beck1 is offline   Reply With Quote
Old 02-11-2004, 02:39 PM   PM User | #2
meeka007
New Coder

 
Join Date: Jan 2004
Location: Minnesota
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
meeka007 is an unknown quantity at this point
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
meeka007 is offline   Reply With Quote
Old 02-28-2004, 05:45 PM   PM User | #3
oldcrazylegs
Regular Coder

 
oldcrazylegs's Avatar
 
Join Date: Feb 2004
Location: East Moline Illinois USA
Posts: 414
Thanks: 4
Thanked 5 Times in 4 Posts
oldcrazylegs is an unknown quantity at this point
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>
oldcrazylegs is offline   Reply With Quote
Old 01-25-2007, 02:47 AM   PM User | #4
Hazman
New to the CF scene

 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Hazman is an unknown quantity at this point
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.
Hazman is offline   Reply With Quote
Old 01-25-2007, 05:21 AM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 01-26-2007, 04:01 AM   PM User | #6
Scrabble
New Coder

 
Join Date: Jan 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Scrabble is an unknown quantity at this point
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.
Scrabble is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:46 AM.


Advertisement
Log in to turn off these ads.