Share on Google+Share on Google+

JavaScript Navigate Back

This page discusses - JavaScript Navigate Back

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:

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

Here is the code of forwardPage.html:

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

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.

Download Source Code:



Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.