History back() method in JavaScript : The back() method of a history object is used to load the previous page browsed. In our application sometimes we required to go to last opened page, in this case the back() function is used. It is same as the back button of the browser, if no url/page is exist in history then nothing happens. This works same as history.go(-1) method.
Syntax of the back() method :
window.history.back()
Example of the back() method : Here is the sample code which will load the last visited page. If it is first page then nothing will happen when clicked to button.
Sample.html
<!DOCTYPE html>
<html>
<body>
<p>To open the previouse page click to button. </p>
<button onclick="goToBack()">Go Back</button>
<script>
function goToBack() {
window.history.back();
}
</script>
</body>
</html>
0 Comment(s)