Navigation: updateCurrentEntry() method
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The updateCurrentEntry()
method of the Navigation
interface updates the state
of the currentEntry
; used in cases where the state change will be independent of a navigation or reload.
Syntax
js
updateCurrentEntry()
updateCurrentEntry(options)
Parameters
options
Optional-
An options object containing the following properties:
state
-
Developer-defined information to be stored in the associated
NavigationHistoryEntry
once the navigation is complete, retrievable viagetState()
. This can be any data type. You might, for example, wish to store a page visit count for analytics purposes, or store UI state details so the view can be shown exactly as the user last left it. Any data stored instate
must be structured-cloneable.
Return value
None (undefined
).
Exceptions
DataCloneError
DOMException
-
Thrown if the
state
parameter had values included in it that are not structured-cloneable. InvalidStateError
DOMException
-
Thrown if the
Navigation.currentEntry
isnull
, i.e. there is no current history entry. This could occur for example if the current page isabout:blank
.
Examples
You could use something like the following to update the open/closed state of a <details>
element so that the state can be restored when reloading the page or navigating back from somewhere else.
js
detailsElem.addEventListener("toggle", () => {
navigation.updateCurrentEntry({ state: { detailOpen: detailsElem.open } });
});
Specifications
Specification |
---|
Unknown specification # dom-navigation-updatecurrententry |
Browser compatibility
BCD tables only load in the browser