🕓 History Object
Last Updated: 26th October 2025
The History Object allows you to access and control the browser’s session history (the list of pages visited in the current tab).
It is part of the BOM (Browser Object Model) and helps you navigate backward or forward between visited pages.
Hinglish Tip 🗣:
historyobject browser ke “Back” aur “Forward” button ka JavaScript version hai!
🧩 Common Properties
| Property | Description | Example |
|---|---|---|
| length | Returns the number of URLs in the session history | history.length |
⚙️ Common Methods
| Method | Description | Example |
|---|---|---|
| back() | Loads the previous URL in the history list (same as browser Back button) | history.back() |
| forward() | Loads the next URL in the history list (same as browser Forward button) | history.forward() |
| go(n) | Loads a specific page from the session history. Use negative numbers for backward and positive for forward. |
|
| pushState() | Adds a new entry to the session history without reloading the page | history.pushState(, "", "/new-page") |
| replaceState() | Replaces the current history entry without reloading | history.replaceState(, "", "/update") |
Example
console.log("History Length:", history.length);
// Go back one page
// history.back();
// Go forward one page
// history.forward();
// Go back two pages
// history.go(-2);
// Add new entry in history without reload
history.pushState({ user: "John" }, "User Page", "/user");
// Replace current entry
history.replaceState({ page: "home" }, "Home Page", "/home");