Reputation: 556
So I'm making a wordpress site, and as such, I want to keep my custom javascript to a minimum. Basically, I have Page1 and Page2, each with several child pages. In the Page1-children, there are links to the Page2-children. The Page2-children have a "Back" button in them that currently just navigate to Page2. What I'm trying to accomplish is: if the Page2-child was navigated to from a Page1-child, I'd like to set the href of the "Back" button to the page it was navigated from. Here's what I've got so far:
jQuery(document).ready(function($){
$('.application-button').on('click', function(event){
event.preventDefault();
var currURL = window.location;
window.location.href = event.currentTarget.href;
$('.dynamic-link').attr('href', currURL); //<-- .dynamic-link is a class of the Back button
//I figured that if it came after the window.location change, it would still be called
});
});
I'm sorry if the explanation before the code is hard to follow, but I can't really explain it in too much more detail, as it is somewhat work-sensitive.
Any and all help is appreciated!
Upvotes: 0
Views: 115
Reputation: 625
A good way is to navigate to the last page in javascript
<script>
function goBack() {
window.history.back()
}
</script>
<body>
<button onclick="goBack()">Go Back</button>
</body>
http://www.w3schools.com/jsref/met_his_back.asp
In your case :
$('.application-button').on('click', function(event){window.history.back();});
Upvotes: 1