History object
The javascript history object is the window property that is used to load previous, forward, or any particular page. It is a property of the window object and thus can be written as window.history or only history.
Properties of History Object:
PROPERTY | USES |
length | To get the length of the history URLs. |
Methods of History Object:
METHOD | USES |
history.forward() or forward() | To load the next page. |
history.back() or back() | To load the previous page. |
history.go() or go() | To load the given page number. |
Example:
<!DOCTYPE html>
<html>
<head>
<script>
function moveForward() {
window.history.forward()
}
function moveBack() {
window.history.back()
}
</script>
</head>
<body>
<input type="button" value="Forward" onclick="moveForward()">
<input type="button" value="Back" onclick="moveBack()">
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script>
function moveForward() {
window.history.forward()
}
function moveBack() {
window.history.back()
}
</script>
</head>
<body>
<input type="button" value="Forward" onclick="moveForward()">
<input type="button" value="Back" onclick="moveBack()">
</body>
</html>
<!DOCTYPE html> <html> <head> <script> function moveForward() { window.history.forward() } function moveBack() { window.history.back() } </script> </head> <body> <input type="button" value="Forward" onclick="moveForward()"> <input type="button" value="Back" onclick="moveBack()"> </body> </html>