Link to home
Start Free TrialLog in
Avatar of alanmarsham
alanmarsham

asked on

Back Button - How

Is there a way to make a button on my web page do exactly what the 'Back' button does on IE.  I am calling the same page from different locations and would like a back button to return to the previous page without me having to enter a http://somewhere.
Please help.
Avatar of NickRackham
NickRackham

Alan, This should do what you want.

In the <head> section of your page add
<SCRIPT LANGUAGE = "Javascript">


And in the <body> of your page where you want the button to be
</SCRIPT>
 

<A HREF="javascript:history.go(-1);"
</A>  
</SCRIPT>

Regards

Nick
.he's correct...except you don't start the second script with an END tag (</SCRIPT>)..

alternately you can use a simple form button to accomplish it..just put this form somewhere in the <BODY></BODY>...


<form>
          <p align="center"><input type="button" value="  Back  " action="onclick history.back()"
        </form>



.....additionally, you could put a -2 or -3 between the parentheses to send them back two or three  pages...etc...

Cheers..

Steve

well spotted <g>
Avatar of alanmarsham

ASKER

Thanks Steve but I need a graphic not a button.
I have tried typing the code into the HTML but the text goes red after the line <script language="javascript">

if i omit this line then the <a href=javascript:history.go(-1);" is then red.

I have tried combinations but cannot seem to get it to work.

Very frustrated... Alan.
you can use graphics as the button of any form...
you just do this:

<form>
          <input border="0" src="images/YOURBUTTONIMAGE.gif" name="myimagebutton" alt="Click Here!" type="image" width="80" height="30"action="onclick history.back()"
        </form>





Ok, I have done that.  It looks good in the page.  But when i have uploaded it, i click it and nothing happens.
Am I missing something simple.
Ok, I have done that.  It looks good in the page.  But when i have uploaded it, i click it and nothing happens.
Am I missing something simple.
Ok, I have done that.  It looks good in the page.  But when i have uploaded it, i click it and nothing happens.
Am I missing something simple.
I dunno...
....this uses the browser's history cache...
....are you just previewing the page and expecting the button to work..?
you have to venture away from a page first, before you can go BACK...

Steve
doh!
it's "onclick=history.back()"


sorry...
Steve
ASKER CERTIFIED SOLUTION
Avatar of SiteSee
SiteSee

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sitesee, Withdrawing proposed answer as you've effectively sorted this.

Nick
no biggy man..
just trying to help where I can...

BTW Nick, I think your code-booger thing above was contagious...notice mine?... :>)

Steve
:o)

I've just found this one as well,

This code in the <head>
-----------------------------------
<SCRIPT LANGUAGE = "Javascript">

image1 = new Image();
image1.src = "backbut1.gif";
image1on = new Image();
image1on.src = "backbut2.gif";

function on3(name) {
document[name].src = eval(name + "on.src");
}
function off3(name) {
document[name].src = eval(name + ".src");
}
NN3 = true;

function on(name) {
if (NN3) on3(name);
}
function off(name) {
if (NN3) off3(name);
}

</SCRIPT>
---------------------------------------

The Code to be placed in the <BODY>

---------------------------------------
<A HREF="javascript:history.go(-1);"
onmouseover="on('image1');" onmouseout="off('image1')">
<IMG SRC="backbut1.GIF" WIDTH=110 HEIGHT=30 BORDER=0
ALT="JavaScript Back-A-Page Button" NAME="image1"></A>  

This one looks good too :o)

Original source http://members.tripod.com/~mclh/backapage.html

Nick
BRILLIANT
Thanks for your patience.  I works perfectly.  I am in your debt.
Many Thanks
Alan...