The JavaScript history back() method is used to navigate the browser back to the previous page in the history. It does not take any arguments and does not return a value.
Here are some examples of how the back() method can be used in JavaScript code:
- To navigate the browser back to the previous page in the history, you can use the following code:
// navigate the browser back to the previous page in the history
history.back();
- To navigate the browser back to the previous page in the history with a custom message, you can use the following code:
// navigate the browser back to the previous page in the history with a custom message
history.back('Navigating back to the previous page...');
- To navigate the browser back to the previous page in the history and execute a callback function, you can use the following code:
// define a callback function
function onNavigateBack() {
// do something...
}
// navigate the browser back to the previous page in the history and execute the callback function
history.back(onNavigateBack);
Overall, the back() method provides a convenient way to navigate the browser back to the previous page in the history. It can be useful for tasks such as implementing a “back” button or link, or for other operations that require navigating the browser back to the previous page in the history.
Leave a Reply