PASSWORD RESET

Your destination for complete Tech news

How to go back to the previous page in Javascript?

2.05K 0
< 1 min read


You can use the window.history object to navigate back to the previous page in JavaScript. The history object provides methods to manipulate the browser’s session history, including moving backward or forward in the history stack. To go back to the previous page, you can use the back() method:

// Go back to the previous page
function goBack() {
  window.history.back();
}

// Call the function to navigate back
goBack();

Alternatively, you can also use the history.go(-1) method to achieve the same result:

// Go back to the previous page
function goBack() {
  window.history.go(-1);
}

// Call the function to navigate back
goBack();

Both of these methods will simulate the user clicking the browser’s back button and take them to the previous page in the session history.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.