What are the methods in JavaScript for going back to the previous page?

There are several ways to go back to the previous page in JavaScript.

  1. By using the go() method of the browser’s history object with a parameter of -1, you can go back to the previous page.
window.history.go(-1);
  1. You can also go back to the previous page using the back() method of the browser’s history object.
window.history.back();
  1. Setting the href property of the browser’s location object to document.referrer indicates the URL of the previous page.
window.location.href = document.referrer;

These methods can all be used to go back to the previous page, the specific method used depends on the specific needs and scenario.

bannerAds