EN
JavaScript - navigate back to previous page
3
points
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.ghistory.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>