I want to call a function on back button click, I am using the below code which is working on both forward and back button but I want only back button click. Not be able to differentiate between Back and Forward click.
if (window.history && window.history.pushState) {
window.history.pushState('forward', null, './#forward');
$(window).on('popstate', function() {
alert('Back button was pressed.');
});
}