...

View Full Version : "Back" button



Beck1
02-11-2004, 01:37 PM
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

meeka007
02-11-2004, 02:39 PM
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

oldcrazylegs
02-28-2004, 05:45 PM
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>

Hazman
01-25-2007, 02:47 AM
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.

felgall
01-25-2007, 05:21 AM
Why clutter up the code with things that aren't needed. Here's the short version:

<span onclick="history.back();">Back</span>

Scrabble
01-26-2007, 04:01 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum