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
- Clear cookie example
- JavaScript getElementById innerHTML
- JavaScript getElementById Style
- Javascript Examples
- JavaScript add row dynamically to table
- New Page 1
- JavaScript Change link
- JavaScript Checkbox getElementById
- javascript clear textarea
- JavaScript Clock Timer
- JavaScript Cookies
- JavaScript Date Difference
- JavaScript duplicate string
- JavaScript Email Validation
- javascript focus input
- JavaScript get excel file data
- JavaScript getAttribute Href
- JavaScript getAttribute Style
- JavaScript getElementById div
- JavaScript getElementById Iframe
- JavaScript getElementById select
- JavaScript Hide Button
- JavaScript Hide Div
- JavaScript hide image
- JavaScript Hide Table Column
- JavaScript Hide Table Rows
- JavaScript Key Event
- JavaScript link
- JavaScript method location
- JavaScript move div
- JavaScript move file
- JavaScript move image
- JavaScript Navigate Back
- JavaScript navigate to page
- JavaScript Navigate to URL
- JavaScript indexOf substring
- JavaScript onkeypress event
- JavaScript Open file
- JavaScript Open link in new window
- JavaScript Open Modal Window