JavaScript Navigate Back

This page discusses - JavaScript Navigate Back

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:

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

Download Source Code: