Javascript go back to previous page

You can use “back ()” in window.history to return to the previous page.

<button onclick="goBack()">Go Back</button>
<script>
function goBack() {
   window.history.back();
}
</script>

Note:

The back() method loads the previous URL in the history list.
This is the same as clicking the “Back button” in your browser, or history.go(-1).
This method will not work if the previous page does not exist in the history list.

Add a Comment

Your email address will not be published. Required fields are marked *