popstate
event does not get fired when clicking on the browser back button this is my code
$(document).ready(function() {
if (window.history && window.history.pushState) {
window.history.pushState('forward', null, './#forward');
$(window).on('popstate', function() {
alert('Back button was pressed.');
});
}
});
When put this code in the console it works but when I put in the file and try to load the page and click on the back button nothing happens. It redirects me to the previous page no alert. I noticed if do not do anything on the screen then it does not work but if you click on scroll on the screen then the popstate event gets called