0% found this document useful (0 votes)
35 views

Developer Mozilla Org en US Docs Web API History

The History interface allows manipulation of the browser session history and pages visited in the current tab or frame. It contains properties like length to get the number of session history entries and state to get the state at the top of the history stack. It also contains methods like back() and forward() to navigate back and forward, and go() to load a specific session history entry by relative location. The pushState() and replaceState() methods allow adding and updating entries in the session history stack with custom data. The History interface is only available on the main thread and not in worker or worklet contexts.

Uploaded by

Seven Jusovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Developer Mozilla Org en US Docs Web API History

The History interface allows manipulation of the browser session history and pages visited in the current tab or frame. It contains properties like length to get the number of session history entries and state to get the state at the top of the history stack. It also contains methods like back() and forward() to navigate back and forward, and go() to load a specific session history entry by relative location. The pushState() and replaceState() methods allow adding and updating entries in the session history stack with custom data. The History interface is only available on the main thread and not in worker or worklet contexts.

Uploaded by

Seven Jusovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

References History

History

The History interface allows manipulation of the browser session history, that is the
pages visited in the tab or frame that the current page is loaded in.

There is only one instance of history ﴾It is a singleton.﴿ accessible via the global object
history .

Note: This interface is only available on the main thread ﴾ Window ﴿. It cannot be
accessed in Worker or Worklet contexts.

Instance properties
The History interface doesn't inherit any property.

length Read only

Returns an Integer representing the number of elements in the session history,


including the currently loaded page. For example, for a page loaded in a new tab this
property returns 1 .

scrollRestoration

Allows web applications to explicitly set default scroll restoration behavior on history
navigation. This property can be either auto or manual .

state Read only

Returns an any value representing the state at the top of the history stack. This is a
way to look at the state without having to wait for a popstate event.
Instance methods
The History interface doesn't inherit any methods.

back()

This asynchronous method goes to the previous page in session history, the same
action as when the user clicks the browser's Back button. Equivalent to
history.go(‐1) .

Calling this method to go back beyond the first page in the session history has no
effect and doesn't raise an exception.

forward()

This asynchronous method goes to the next page in session history, the same action
as when the user clicks the browser's Forward button; this is equivalent to
history.go(1) .

Calling this method to go forward beyond the most recent page in the session history
has no effect and doesn't raise an exception.

go()

Asynchronously loads a page from the session history, identified by its relative
location to the current page, for example ‐1 for the previous page or 1 for the next
page. If you specify an out‐of‐bounds value ﴾for instance, specifying ‐1 when there
are no previously‐visited pages in the session history﴿, this method silently has no
effect. Calling go() without parameters or a value of 0 reloads the current page.

pushState()

Pushes the given data onto the session history stack with the specified title ﴾and, if
provided, URL﴿. The data is treated as opaque by the DOM; you may specify any
JavaScript object that can be serialized. Note that all browsers but Safari currently
ignore the title parameter. For more information, see Working with the History API.

replaceState()

Updates the most recent entry on the history stack to have the specified data, title,
and, if provided, URL. The data is treated as opaque by the DOM; you may specify any
JavaScript object that can be serialized. Note that all browsers but Safari currently
ignore the title parameter. For more information, see Working with the History API.

Specifications
Specification

HTML Standard
# the‐history‐interface

Browser compatibility
BCD tables only load in the browser

See also
history global object

Found a content problem with this page?

Edit the page on GitHub.

Report the content issue.

View the source on GitHub.

Want to get more involved? Learn how to contribute.

This page was last modified on Mar 29, 2023 by MDN contributors.

Your blueprint for a better internet.


MDN
About
Blog
Careers
Advertise with us

Support
Product help
Report an issue

Our communities
MDN Community
MDN Forum
MDN Chat

Developers
Web Technologies
Learn Web Development
MDN Plus
Hacks Blog

Website Privacy NoticeCookiesLegalCommunity Participation Guidelines

Visit Mozilla Corporation’s not‐for‐profit parent, the Mozilla Foundation.


Portions of this content are ©1998–2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

You might also like