So, we all surf the internet to watch YouTube videos and Stackoverflow and many more. And we usually click "←" this button to go back to the previous website.
Do you know? You can create the same functionality of "←" this button of browser in Javascript 🔥
Let's create a back button
<button>Go Back</button>
It's time to make it functional ✌️
- Add
onclick
attribute to the button
onclick="history.back()"
- Here's the final and little code 🙂
<button onclick="history.back()">Go Back</button>
How does this work?
The history.back()
method loads the previous URL from the history list. It will only work if the previous page exists.
Check out video demo
Try it live by yourself: Live demo (Open this link in this tab only since it will create a previous page 🙂 )
Feel free to reach me out via Twitter - @codewithsnowbit
🌏 Let's connect
Stay tuned for the next article. Stay safe and Happy Coding!
Our Amazing SponsorsDigitalOcean offers a simple and reliable cloud hosting solution that enables developers to get their website or application up and running quickly.View Website
Laravel News keeps you up to date with everything Laravel. Everything from framework news to new community packages, Laravel tutorials, and more.View Website
A Laravel Starter Kit that includes Authentication, User Dashboard, Edit Profile, and a set of UI Components. Learn more about the DevDojo sponsorship program and see your logo here to get your brand in front of thousands of developers.View Website
If you enjoyed and find my content helpful, then you can check this out
Comments (0)