JavaScript Window History
The window.history object contains the browser's history.
Window History
window.historyThe object can be written without the window prefix.
To protect user privacy, restrictions are imposed on JavaScript's access to the methods of this object.
Some methods:
- history.back() - same as clicking the back button in the browser
- history.forward() - same as clicking the forward button in the browser
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:
Examples
Create a back button on the page:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<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()
The history.forward() method loads the next URL in the history list.
This is the same as clicking the forward button in the browser:
Examples
Create a forward button on the page:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<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:
Other Extensions