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.