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.
alanmarshamAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
SiteSeeConnect With a Mentor Commented:
oops...still not right, huh?...

here it is...100% correct:

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

sorry bout that...in a hurry ya know..

Steve









0
 
NickRackhamCommented:
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
0
 
SiteSeeCommented:
.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

0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
NickRackhamCommented:
well spotted <g>
0
 
alanmarshamAuthor Commented:
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.
0
 
SiteSeeCommented:
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>





0
 
alanmarshamAuthor Commented:
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.
0
 
alanmarshamAuthor Commented:
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.
0
 
alanmarshamAuthor Commented:
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.
0
 
SiteSeeCommented:
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
0
 
SiteSeeCommented:
doh!
it's "onclick=history.back()"


sorry...
Steve
0
 
NickRackhamCommented:
Sitesee, Withdrawing proposed answer as you've effectively sorted this.

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

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

Steve
0
 
NickRackhamCommented:
: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
0
 
alanmarshamAuthor Commented:
BRILLIANT
Thanks for your patience.  I works perfectly.  I am in your debt.
Many Thanks
Alan...
0
All Courses

From novice to tech pro — start learning today.