I have taken over a WordPress site in which I need to add back buttons within the site.
The browser url is always the same and you have to use navigations buttons that are built-in.
A link is set up as:
<a href="#" data="url">Link text</a>
When someone clicks the link it loads the new page/post within the div container.
I need to find a way to have a user go back to the previous "page" when clicking this custom back button. Like somehow remember the previous page's data attribute then using that to go back.
I really have no idea how to approach this...
You can use javascript history method like this:
<a href="#" data-url="http://previous-url" id='goBack'>Link text</a>
<script>
$('#goBack').click(function (e) {
e.preventDefault();
var url_to_go = $(this).attr('data-url');
window.location.href = url_to_go;
});
</script>