Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JavaScript Window History


May 06, 2021 JavaScript


Table of contents


JavaScript Window History


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


Window History

Window.history objects can be written without the prefix window.

To protect user privacy, JavaScript's access to the object is restricted.

Some methods:


Window History Back

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

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

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 above code output is:



Window History Forward

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

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

Create a forward button on the page:

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

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

</body>
</html>

The above code output is:



Related articles

JavaScript Standard Reference Tutorial: JavaScript History Object