Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The forward()
method of the Navigation
interface navigates forwards by one entry in the navigation history.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The forward()
method of the Navigation
interface navigates forwards by one entry in the navigation history.
js
forward(options)
options
Optional
An options object containing the following properties:
info
Developer-defined information to be passed along to the navigate
event, made available in NavigateEvent.info
. This can be any data type. You might, for example, wish to display newly-navigated content with a different animation depending on how it was navigated to (swipe left, swipe right, or go home). A string indicating which animation to use could be passed in as info
.
An object with the following properties:
committed
A Promise
which will fulfill when the visible URL has changed and a new NavigationHistoryEntry
has been created.
finished
A Promise
which will fulfill when all promises returned by the intercept()
handler are fulfilled. This is equivalent to the NavigationTransition.finished
promise fulfilling, when the navigatesuccess
event fires.
Either one of these promises rejects if the navigation has failed for some reason.
InvalidStateError
DOMException
Thrown if the Navigation.currentEntry
's NavigationHistoryEntry.index
value is -1 or Navigation.entries().length - 1
, i.e. either the current Document
is not yet active, or the current history entry is the last one in the history, meaning that forwards navigation is not possible.
js
async function backHandler() { if (navigation.canGoBack) { await navigation.back().finished; // Handle any required clean-up after // navigation has finished } else { displayBanner("You are on the first page"); } } async function forwardHandler() { if (navigation.canGoForward) { await navigation.forward().finished; // Handle any required clean-up after // navigation has finished } else { displayBanner("You are on the last page"); } }
Specification |
---|
HTML Standard # dom-navigation-forward-dev |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
forward |
102 | 102 | No | No | 88 | No | 102 | 102 | No | 70 | No | 19.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Navigation/forward