title: How can I detect either back or forward button of the browser is pressed?
body: <p>I have two customized functions that handle back and forward page. I need to call them when user clicks on the browser back/forward buttons too. </p>
  
  <pre><code>window.onpopstate  = function() {
  
      if ( /* back button clicked */ ){
  
          showPreviousPage():
  
      } else {
  
          showNextPage();
  
      }
  
  })
  </code></pre>
  
  <p>How can I implement that condition? In other word, how can I detect browser back button is clicked?</p>