I want to catch the browser back button before any thing happened to page. I have looked into many solutions, some catch this event when the previous page is loaded fully, I don't need that. I need to catch it before even any thing happen. I found another good solution,
$(window).on('popstate', function() {
var hashLocation = location.hash;
var hashSplit = hashLocation.split("#!/");
var hashName = hashSplit[1];
if (hashName !== '') {
var hash = window.location.hash;
if (hash === '') {
alert('Back button was pressed.');
}
}
});
window.history.pushState('forward', null, '#b');
}
Quite effective solution, this catch back button event before even anything happened to the page but this write #b with my URL, which is not acceptable.
Need help, to catch any browser back button, before even any thing happen to the page.
Actually, my complete story is, When back is pressed i store a variable in cookie. Soon script is first hit on page load, i check cookie, theni reload the whole page. So that a server side is call generated instead of cache. Any alternative solution?
I am looking for a solution for a quite long time, but no effective solution found yet. Thanks in advance.