WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Window History


The window.history object contains the history of the browser.


Window History

window.history Objects can be written without the window prefix.

To protect user privacy, restrictions have been placed on how JavaScript can access this object.

Some methods:

  • history.back ()-same as clicking the back button in the browser
  • history.forward ()-same as clicking the forward button in a browser

Window History Back

history.back () method loads the previous URL in the history list.

This is the same as clicking the back button in a browser:

Example

Create a back button on the page:

<html>
<head>
<script>
function goBack() {
    window.history.back()
}
</script>
</head>
<body>

<input type="button" value="Back" onclick="goBack()">

</body>
</html>

The output of the above code is:


Window History Forward

history forward () method loads the next URL in the history list.

This is the same as clicking the forward button in a browser:

Example

Create a forward catch on a page:

<html>
<head>
<script>
function goForward() {
    window.history.forward()
}
</script>
</head>
<body>

<input type="button" value="Forward" onclick="goForward()">

</body>
</html>

The output of the above code is: