- Instant help with your JavaScript coding problems

Go back to previous page with JavaScript

Question:
How to go back to previous page with JavaScript?
Answer:
const backBtn = document.getElementById('back-btn');

backBtn.addEventListener('click', ()=>{
    window.history.back();
});
Description:

You can send your website visitor back to the previous page by using the History interface. The History interface allows manipulation of the browser session history, that is the pages visited in the tab or frame that the current page is loaded in. The History.back() method causes the browser to move back one page in the session history.

Share "How to go back to previous page with JavaScript?"
Tags:
previous page, go back, redirect, javascript, history
Technical term:
Go back to previous page with JavaScript