sajad torkamani

In a nutshell

Explain like I’m five.

The History interface lets you manipulate the browser’s session history – the pages visited in the current tab or iframe.

Recipes

Get number of elements in the session history

history.length

This will include

Go to the previous page in session history

history.back() // equivalent to history.go(-1)

This is the same action as when the user clicks the browser’s back button. When there’s no previous page, nothing happens.

Go to the next page in session history

history.forward() // equivalent to history.go(1)

This is the same action as when the user clicks the browser’s forward button. When there’s no next page, nothing happens.

Go to specific page in session history

history.go(1) // Go to the next page in session history
history.go(2) // Go forward two pages
history.go(-1) // Go to the previous page
history.go() // Reload the current page
history.go(0) // Reload the current page

Add an entry to the session history stack

history.pushState(state, unused, url)

See History.pushState for more details.

Replace current entry

history.replaceState(state, unused, url)

See History.replaceState for more details.

Sources

Tagged: Web APIs