Esta tradução está incompleta. Por favor, ajude a traduzir este artigo.

{APIRef ("HTML DOM")}}

A interface History permite a manipulação do histórico da sessão do navegador, ou seja, as páginas visitadas na guia ou quadro em que a página atual está carregada.

Propriedades

 

A interface History não herda nenhuma propriedade.

History.length Somente leitura
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.
History.current Somente leitura Obsolete since Gecko 26
Returns a DOMString representing the URL of the active item of the session history. This property was never available to web content and is no more supported by any browser. Use Location.href instead.
History.next Somente leitura Obsolete since Gecko 26
Returns a DOMString representing the URL of the next item in the session history. This property was never available to web content and is not supported by other browsers.
History.previous Somente leitura Obsolete since Gecko 26
Returns a DOMString representing the URL of the previous item in the session history. This property was never available to web content and is not supported by other browsers.
History.scrollRestoration 
Allows web applications to explicitly set default scroll restoration behavior on history navigation. This property can be either auto or manual.
History.state Somente leitura
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.

Methods

The History interface doesn't inherit any methods.

History.back()
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.
History.forward()
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.
History.go()
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. Internet Explorer lets you specify a string, instead of an integer, to go to a specific URL in the history list.
History.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 Firefox currently ignores the title parameter; for more information, see manipulating the browser history.
History.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 Firefox currently ignores the title parameter; for more information, see manipulating the browser history.

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'History' in that specification.
Padrão em tempo real Adds the scrollRestoration attribute.
HTML5
The definition of 'History' in that specification.
Recomendação Initial definition.
Custom Scroll Restoration - History-based API
The definition of 'History' in that specification.
Rascunho Adds the scrollRestoration attribute.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
backChrome Full support YesEdge ? Firefox Full support YesIE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?
forwardChrome Full support YesEdge ? Firefox Full support YesIE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?
goChrome Full support YesEdge ? Firefox Full support YesIE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?
lengthChrome Full support YesEdge ? Firefox Full support YesIE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?
pushStateChrome Full support 5Edge Full support YesFirefox Full support 4
Notes
Full support 4
Notes
Notes In Firefox 2 through 5, the passed object is serialized using JSON. Starting in Firefox 6, the object is serialized using the structured clone algorithm. This allows a wider variety of objects to be safely passed.
IE Full support 10Opera Full support 11.5Safari Full support 5WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support 4.3Samsung Internet Android ?
replaceStateChrome Full support 5Edge Full support YesFirefox Full support 4
Notes
Full support 4
Notes
Notes In Firefox 2 through 5, the passed object is serialized using JSON. Starting in Firefox 6, the object is serialized using the structured clone algorithm. This allows a wider variety of objects to be safely passed.
IE Full support 10Opera Full support 11.5Safari Full support 5WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support 4.3Samsung Internet Android ?
scrollRestorationChrome Full support 46Edge No support NoFirefox Full support 46IE No support NoOpera Full support 33Safari Full support YesWebView Android No support NoChrome Android Full support 46Edge Mobile No support NoFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
stateChrome Full support YesEdge ? Firefox Full support YesIE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

See also

  • The Window.history property returning the history of the current session.

Etiquetas do documento e colaboradores

Colaboradores desta página: Renancp01
Última atualização por: Renancp01,