title: How to display confirmation if user clicks on a back browser button?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/136937/is-there-a-way-to-catch-the-back-button-event-in-javascript">Is there a way to catch the back button event in javascript?</a>  </p>
  </blockquote>
  
  
  
  <p>In my application I want only a certain number of scripts (Text1.php, Text2.php and Text3.php) to contain a piece of code where that if the user clicks on the back browser button, it will display a confirmation box like the one below:</p>
  
  <pre><code>confirm("You have clicked on the browser's back button. If you confirm to go back via the browser back button, you will be logged out and lose your current assessment details." + "\n" + "\n" + "Are you sure you want to go back and lose current assessment details?" + "\n" );
  </code></pre>
  
  <p>The requirments are the following:</p>
  
  <ol>
  <li>How to show the confirm if the user clicks on the back browser button?</li>
  <li>If user confirms the confirmation then navigate to Text4.php (This is where it logs out user)</li>
  <li>If user cancels confirmation then just close confirmation box so user can continue what they are doing (guessing this is something to do with <code>return false;</code></li>
  <li>Only want this to happen for scripts (Text1.php, Text2.php and Text3.php) </li>
  <li>Need it to work on all major browsers (IE, Chrome, Firefox, Safari, Opera)</li>
  </ol>
  
  <p>Thank you</p>