JavaScript history back() method

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:

  1. 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();
  1. 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...');
  1. 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: