Jquery when back button is pressed

back, browser, jquery

Solution

You can sort of do it using the popstate event:

window.onpopstate = function() {
  alert("pop!");
}

or in jQuery:

$(window).on('popstate', function(event) {
 alert("pop");
});

However this will also trigger when navigating forward, not only backward.

Problem

I have a click that changes things on the page when you click it. I was wondering if there was a way to trigger an effect when you press the back button on the browser

Original source