Back to all resources
jQuery
browser history
navigation

Back / Foward Buttons

By Corey Moen
This JavaScript code snippet provides functionality for navigating the browser history. It uses jQuery to attach click event handlers to elements with the classes .goback and .goforward. When an element with the class .goback is clicked, the browser navigates to the previous page in the history stack using window.history.back(). Similarly, when an element with the class .goforward is clicked, the browser navigates to the next page in the history stack using window.history.forward().


This functionality is useful for creating custom back and forward buttons on a webpage, allowing users to navigate through their browsing history without using the browser's default navigation buttons.