title: Solution for Browser back button tracking
body: <p>I want to track browser back button.
  If the user click on the browser back button, It should ask user to logout in pop-up confirm box. If the user press "ok", user account should log out. If user press "cancel", user should stay on the same page.
  I already visited:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/3681093/confirm-browser-back-button-else-stay-on-page">Confirm browser back button else stay on page</a></li>
  <li><a href="https://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own">How can I override the OnBeforeUnload dialog and replace it with my own?</a></li>
  <li><a href="https://stackoverflow.com/questions/140460/client-js-framework-for-unsaved-data-protection">Client/JS Framework for &quot;Unsaved Data&quot; Protection?</a></li>
  <li><a href="https://stackoverflow.com/questions/3033874/alert-user-when-they-hit-the-browser-back-button-with-good-reson">Alert user when they hit the browser back button - with good reason</a></li>
  </ul>
  
  <p>But I am not getting any positive solution for my problem.
  I already tried this code</p>
  
  <pre><code>window.onbeforeunload = function(evt) {            
      if(confirm('logout ?'))
      {
          return;
      }
      else
      {
          alert('Dont use browser navigations');
          return false;
      }
  }
  </code></pre>
  
  <p><code>If</code> part is perfectly working. But <code>else</code> part, after alert box the browser shows the default dialog box.
  If I use <code>return true</code> instead of <code>return</code> in the <code>if</code> part, the browser pops up the confirm box and shows default dialog box followed that. If I use <code>return</code>, It is just showing the confirm box and proceeds the action.</p>
  
  <p>So, in the same way I'm using return false in <code>else</code> part. If I use <code>return false</code> in <code>else</code> part alert box is display after confirm cancel action. Then browser's default dialog box is asking to leave the page or stay on this page. </p>
  
  <p>I want to use another solution instead of <code>return false</code> to make the condition false. If user click the cancel button in confirm box it should do nothing. It should stay on the same page.
  See the <a href="http://jsfiddle.net/psF6m/" rel="nofollow noreferrer">JSFIDDLE</a> demo</p>