Navigation: forward() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
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.
Syntax
forward(options)
Parameters
optionsOptional-
An options object containing the following properties:
infoOptional-
Developer-defined information to be passed along to the
navigateevent, made available inNavigateEvent.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 asinfo.
Return value
An object with the following properties:
committed-
A
Promisewhich will fulfill when the visible URL has changed and a newNavigationHistoryEntryhas been created. finished-
A
Promisewhich will fulfill when all promises returned by theNavigateEvent.intercept()handler are fulfilled. This is equivalent to theNavigationTransition.finishedpromise fulfilling, when thenavigatesuccessevent fires.
Either one of these promises rejects if the navigation has failed for some reason.
Exceptions
InvalidStateErrorDOMException-
Thrown if the
Navigation.currentEntry'sNavigationHistoryEntry.indexvalue is -1 ornavigation.entries().length - 1, i.e., either the currentDocumentis not yet active, or the current history entry is the last one in the history, meaning that forwards navigation is not possible, or if the currentDocumentis unloading.
Examples
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");
}
}
Specifications
| Specification |
|---|
| HTML> # dom-navigation-forward-dev> |
Browser compatibility
Loading...