1

I tried below codes but that is not consistent.

if (performance.navigation.type == 2) {
    alert("Back button clicked");
}

and,

if (performance.getEntriesByType("navigation")[0].type === 'back_forward') {
   alert("Back button clicked");
}

Please suggest if any other possible ways to Detect back button in browsers.

1 Answers1

0

Try history

(function() {

if (window.history && window.history.pushState) {

    $(window).on('popstate', function() {
  
      alert('Back button was pressed.');
    });
}

})();