Languages
[Edit]
EN

JavaScript - navigate back to previous page

3 points
Created by:
Lani-Skinner
438

In this article, we would like to show you how to navigate back to the previous page using JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

<button onclick="history.go(-1)">
  Navigate to previous page
</button>

Note:

Using this solution you can navigate multiple pages back by specifying different number as history.go() argument (e.g history.go(-2) - go two pages back).

 

Alternarive solution

In this example, we use window.history.back() as an alternative to history.go(-1) to go to the previous page.

// ONLINE-RUNNER:browser;

<!DOCTYPE html>
<html>
<body>
  <button onclick="window.history.back()">
    Navigate to previous page
  </button>
</body>
</html>
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join