How to make the browser go back to the previous page on click with JavaScript?

Spread the love

Sometimes, we want to make the browser go back to the previous page on click with JavaScript.

In this article, we’ll look at how to make the browser go back to the previous page on click with JavaScript.

How to make the browser go back to the previous page on click with JavaScript?

To make the browser go back to the previous page on click with JavaScript, we call history.back.

For instance, we wrire

<input name="action" onclick="history.back()" type="submit" value="Cancel" />

to set the onclick attribute to history.back() to call history.back when we click on the input button to go back to the previous page.

Conclusion

To make the browser go back to the previous page on click with JavaScript, we call history.back.

Leave a Reply

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