Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Back button inside page with Javascript? 1

Status
Not open for further replies.

etu1972

Programmer
Jul 29, 2002
69
US
I want to build a button in an html page that will perform the same function as the browser back button. Is there some javascript that can do this? Thanks, AMc

Should I stay or should I go? Thanks & Goodbye, Joe.
 
Simplest way is to create a button on your page in html, and in the onclick event use the [tt]history.go[/tt] or [tt]history.back[/tt] commands, like so:

history.go
[tt]<input type=button name=backButton id=backButton value=&quot;Back&quot; onclick=&quot;javascript:history.go(-1)&quot;>[/tt]

history.back
[tt]<input type=button name=backButton id=backButton value=&quot;Back&quot; onclick=&quot;javascript:history.back&quot;>[/tt]

Either one of those will act the same as the user clicking the back button on the browser.

Info found at Good resource for JavaScript stuff.

HTH,
jp
 
Thanks JP, that did the trick. AMc

Should I stay or should I go? Thanks & Goodbye, Joe.
 
Is there a way to change the initial Back button text and background colors? Set color attributes for the button? Thanks, AMc

Should I stay or should I go? Thanks & Goodbye, Joe.
 
with <a href=javascript:history.go(-1)>Go Back</a>, you can do whatever you want to deal with color, font, background,...

or you can use a graphic with smthg like this...

<a href=# onClick=javascript:history.go(-1)><img src=whateveryoulike.jpg></a>

hope this help...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top