I have searched high and low for this but I can't seem to find anything for my specific use-case.
I want to detect when user clicks the browser's back button and do something. Specifically, when a user clicks the back button another element on the page will be clicked instead of actually going back to the previous page.
EDIT: This is not a duplicate. I am aware of that thread and we have different use-case. I don't think that will work for me. jQuery address only works for browser history so that when the back button is clicked it will load the previous content in ajax. Perfect for the former's use-case. However mine is different.
I have a simple text page.
<div>
<p> foo foo foo foo foo foo foo </p>
<a href="" id="1"> </a>
<a href="" id="2"> </a>
<a href="" id="3"> </a>
</div>
Now when the browser's back button is clicked I want to user to redirect to id 3 instead of going back to the previous page.
Unless I'm missing something here? How can I use jQuery address to achieve what I want?
Furthermore, I found this. Browser Back Button Detection Where you could do something like this when you use his backfix.min.js:
<script type="text/javascript" src="backfix.min.js"></script>
<script type="text/javascript">
bajb_backdetect.OnBack = function()
{
alert('You clicked it!');
}
</script>
Working as it should but I can't seem to make it work in my case. I'm trying to do the following but it just doesn't work:
<script type="text/javascript">
bajb_backdetect.OnBack = $(function() {
$("a#3").trigger('click');
});
</script>
This is probably where I'm messing up. So I need your help here.
Nonetheless. I am still open to any possible solution. Thanks.