History forward() method in JavaScript : The forward() method of a history object is used to load the next page browsed. In our application sometimes we required to go to next opened page, in this case the forward() function is used. It is same as the forward 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 forward() method :
window.history.forward()
Example of the forward() method : Here is the sample code which will load the next visited page from the browser history. If it is first page or no next page exist in history then nothing will happen when clicked to button.
Sample.html
<!DOCTYPE html>
<html>
<body>
<p>To open the next page click to button. </p>
<button onclick="goToNext()">Go Next</button>
<script>
function goToNext() {
window.history.forward();
}
</script>
</body>
</html>
0 Comment(s)