HTML and JavaScript code for back button in to go previous pages

<input type="button" 
    value="Back" 
    onClick="history.go(-1);">
History Back We can add a back button in HTML to navigate to the previous page. Clicking the button works like the browser's back button, allowing users to go back one or multiple steps. The button can be placed anywhere in the page. Below is the simple code for it.
<INPUT TYPE="button" VALUE="Back" onClick="history.go(-3);">

Demo of returning to previous page by using back button
You can read more on history object of JavaScript here This code will display one button and you can change the value parameter to display any text on the button. Here is the button to take you back to previous page. Note that the onClick event can be set to history.go(-3); to move back three steps. We can use +2 also to move forward two steps.

Using JavaScript

We can use JavaScript to create a link to take us back to previous or history page. Here is the code to move back the browser using client side JavaScript.
<a href="javascript:history.back()">
    Back to previous page
</a>
As you can see this requires JavaScript to be enabled in the client browser. Otherwise this code will not work.
HTML Form Submit form data to new window Using buttons to link different pages


plus2net.com







Donna Calcavecchio

26-01-2012

I want the user to go back to the same spot the click on link appears after he closes a linked page
mohammed

09-04-2012

thank you thank you again you saved me from searching for fays you are the best
Frank

27-07-2012

Excellent! Exactly what I was looking for. Thanks
SHAMEEL KT

06-01-2013

Excellent....
narendra

30-01-2013

nice dear...thanks
mary

02-04-2013

Thanks! Just what I needed
Rahul

16-04-2013

thank u sir
hanumantha

30-07-2013

Nice one
Richard

19-01-2014

Is there a way to utilize a back button to manipulate an iframe?
Abdul_Karim

23-09-2014

Thanks Exactly the thing what I was looking for
Ashish

06-11-2014

i want page will be load on back button click..
kingwash

31-10-2016

That's great. Saves me millions of time.
Paul

05-11-2016

Works perfectly. Thanks so much pal

22-01-2021

Thanks a lot



We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer