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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
NickRackhamCommented:
well spotted <g>
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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
SiteSeeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development Software

From novice to tech pro — start learning today.