Javascript history back function redirects the user to the previous page visited by the user. History Back function of javascript performs the same action as the web browser back arrow button. But remember that javascript history back button works at client side that does not retrieve the updated version of web page if in the mean time original content of the web page changes on the server. Javascript history back function displays the cached version of the web page stored at client side.
Syntax for Javascript History Back Function
history.back();
or
window.history.back();
You can also use window object of javascript to access back the method of history object.
Example of Javascript History Back Function
<html>
<head>
<title>Javascript History Object Back Function</title>
</head>
<body>
<input
id="btnBack"
type="button"
value="Back"
onclick="history.back();" />
</body>
</html>
Above example creates a back button on the HTML page. onclick event is used to redirect the user to previous URL of the web browser history.
Continue to next tutorial: Javascript History Forward Function to learn how to navigate to next link using JavaScript function.