JavaScript Navigate Back
In this section, you will learn how to navigate back to the main page using JavaScript.
In this tutorial, we will learn how to navigate back to the page where the user came from. JavaScript provides several methods for this purpose. To illustrate this section, we have created two html pages page.html and forwardPage.html. In page.html, we have simply created a form and a link. When the user click the link, he/she will move to the next page i.e. 'forwardPage.html' where we have used the method javascript:history.go(-1) which allow the user to navigate back to the 'page.html'.
Here is the code of page.html:
| <html> <h3>Form</h3> <form> <table> <tr><td>Enter Name:</td><td><input type="text"></td></tr> <tr><td>Enter Address:</td><td><input type="text"></td></tr> <tr><td><a href="forwardPage.html">Next</a></td></tr> </table> </form> </html> |
Here is the code of forwardPage.html:
| <html> <table> <tr><td>Your Qualifications:</td> <td><textarea rows="2" cols="20"></textarea><td></tr> <tr><td><a href="javascript:history.go(-1)">Go back</a></td></tr> <table> </html> |
Output will be displayed as:

On clicking the link, you will move to the next page:
On clicking the link 'Go Back', you will move back to the main page i.e. page.html.
Tutorials
- Java 26 (JDK 26) Features with examples
- Top 10 Reasons to Learn Java in 2026
- JDK 26 Tutorial
- Java Certification Roadmap 2026: Which Oracle Certs Matter
- Install JDK 26: A Complete Beginner's Guide (2026)
- What Is Java? A Complete, Up-to-Date Guide for 2026
- Java 26 HTTP3 tutorial - HTTP 3 support in JDK 26 - How to use HTTP/3 in Java 26 application?
- JDK 28 Preview: Value Objects, Shenandoah GC & JSON API
- Java Tutorials


