JAVASCRIPT Tutorial
window.history
property to access the history object.length
property to retrieve the number of pages in the history, or use the entries()
method to get an array of history entries.back()
and forward()
methods to navigate backward and forward in history, respectively.go()
method to jump to a specific entry in history, and the pushState()
and replaceState()
methods to add or replace entries.// Get the current page's position in history
let historyPosition = window.history.length;
// Navigate one page back in history
window.history.back();
// Push a new entry to history
window.history.pushState({}, 'New Page', '/new-page');
// Replace the current entry in history
window.history.replaceState({}, 'Updated Page', '/updated-page');