WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Window History


The window.history object contains the programs history.


Window History

The window.history item can be composed without the window prefix.

To ensure the protection of the clients, there are impediments to how JavaScript can get to this object.

Some methods:

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

Window History Back

The history.back() technique stacks the past URL in the history list.

This is equivalent to tapping the Back catch in the browser.

Example

Create a back catch on a page:

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

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

</body>
</html>

The yield of the code above will be:


Window History Forward

The history forward() technique stacks the following URL in the history list.

This is equivalent to tapping the Forward catch in the browser.

Example

Create a forward catch on a page:

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

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

</body>
</html>

The yield of the code above will be: