title: Controlling the Back button using onhashchange or jquery
body: <p>I need some guidance on how to have very basic control in the use of the back button.</p>
  
  <p>Basically, I need to warn the user that by clicking the back button, when on my checkout.asp page, they will lose the items already there.  I need to instruct them to use the navigation buttons instead.</p>
  
  <p>I've had a look around a have seen mention of the onhashchange event but I could not get it to work.</p>
  
  <p>I also tried the plugin by Ben Alman:</p>
  
  <pre><code>&lt;script type="text/javascript" src="jquery/js/jquery-1.6.2.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="jquery/js/jquery-ui-1.8.16.custom.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="jquery/js/jquery.ba-hashchange.js"&gt;&lt;/script&gt;
  
  &lt;script language="JavaScript" type="text/JavaScript"&gt;
  $(function(){
      // Bind the event.
      $(window).hashchange( function(){
      // Alerts every time the hash changes!
      alert( location.hash );
      })
      // Trigger the event (useful on page load).
      $(window).hashchange();
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>This only fires up the alert (with no value from the location.hash) when entering the page but I simply want to warn the user if they're leaving. If they choose to stay then let them press cancel to leave them on the same page.</p>
  
  <p>Any help appreciated.</p>