Window History
The window.history
object can be written without the window prefix.
To protect the privacy of the users, there are limitations to how JavaScript can access this object.
Some methods:
history.back()
- same as clicking back in the browser
history.forward()
- same as clicking forward 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.
Example(1)
<input class="btn btn-success" type="button" value="Back" onclick="goBack()"> <script> function goForward() { window.history.forward() } </script>
In above example Created a back button on a page.
Example(2)
<input class="btn btn-success" type="button" value="Forward" onclick="goForward()"> <script> function goBack() { window.history.back() } </script>
<!DOCTYPE html> <html> <head> <title>How To Use Window History Objects With Java Script</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> </head> <body> <div class="container"> <br> <div class="text-center"> <h1 id="color" style="color: tomato">How To Use Window History Objects With Java Script</h1> </div> <div class="well"> <input class="btn btn-success" type="button" value="Back" onclick="goBack()"> <input class="btn btn-success" type="button" value="Forward" onclick="goForward()"> <script> function goForward() { window.history.forward() } function goBack() { window.history.back() } </script> </div> </div> </body> </html>