JS Tutorial
Menu
JS Version
Menu
JS Objects
Menu
JS Function
Menu
JS Classes
Menu
JS Async
Menu
JS HTML DOM
Menu
JS Browser BOM
Menu
JS Web API
Menu
JS AJAX
Menu
JS JSON
Menu
JS vs JQUERY
Menu
JS Graphics
Menu
Web History API
The History back() Method
The back() method is used to load the previous URL in the windows.history list.
It is the similar as clicking the “back arrow” in your browser.
Example
<button onclick=”myFunction()”>Go Back</button>
<script>
function myFunction() {
window.history.back();
}
</script>
The History go() Method
The go() method is used to load a definite URL from the history list:
Example
<button onclick=”myFunction()”>Go Back 2 Pages</button>
<script>
function myFunction() {
window.history.go(-2);
}
</script>
History Object Properties
Property | Description |
length | Returns the number of URLs in the history list |
History Object Methods
Method | Description |
back | Loads the previous URL in the history list |
forward() | Loads the next URL in the history list |
go() | Loads a specific URL from the history list |