Categories
JavaScript Answers

How to create a ‘Go Back’ link that takes the user to a link if there’s no history for the tab or window with JavaScript?

Spread the love

Sometimes, we want to create a ‘Go Back’ link that takes the user to a link if there’s no history for the tab or window with JavaScript.

In this article, we’ll look at how to create a ‘Go Back’ link that takes the user to a link if there’s no history for the tab or window with JavaScript.

How to create a ‘Go Back’ link that takes the user to a link if there’s no history for the tab or window with JavaScript?

To create a ‘Go Back’ link that takes the user to a link if there’s no history for the tab or window with JavaScript, we call history.back when we click on the link.

For instance, we write

<a href="javascript:history.back();">Go Back</a>

to call history.back when we click on the Go Back link to go back to the previous page.

Conclusion

To create a ‘Go Back’ link that takes the user to a link if there’s no history for the tab or window with JavaScript, we call history.back when we click on the link.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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