JavaScript Window History

The window.history object stores an array of URLs visited by the user. All the url's can whenever loaded gets stored in the object which can be used later to navigate.

The window.history object can be written also without the window prefix like all window objects.


History Object Methods

Property Description
history.back() Works as clicking back button in the browser.
history.forward() Works as clicking forward button in the browser.

Window History Back

The history.back() method loads the previous URL in the history list. It allows the user to load whatever the previous loaded page was in the same tab.

Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> JavaScript Window Window History </title>
<script>
function goBack() {
window.history.back()
}
</script>
</head>
<body>
<input type="button" value="Back" onclick="goBack()">
</body>
</html>

Output

JavaScript Window Window History

Window History Forward

The history.forward() method loads the next URL in the history list. It allows the user to go to the page from which the user came back by clicking backward button.

Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> JavaScript Window History </title>
<script>
function goForward() {
window.history.forward()
}
</script>
</head>
<body>
<input type="button" value="Forward" onclick="goForward()">
</body>
</html>

Output

JavaScript Window History



Color Picker

List of color names supported by all browser »



Character Code

List of character codes to display special character »



Language Code

List of all language supported by all browser »



Country Code

List of Country code supported by all browser »

Latest Updates

PHP Introduction

How to Run a PHP program in Xampp?

How can I create a phpinfo.php page?

How to Define a Variable in PHP

PHP Echo and Print Statements

Working with PHP Operators

Understanding the PHP Data Types

How to Write Comments in PHP

How to Define a Constant in PHP

PHP if...else...elseif Statements