title: Prevent back button jquery mobile
body: <p>I'm working on a jQuery mobile project and need to prevent the user from getting back to certain pages, the UI obviously doesn't provide a back button where the user is not supposed to go back, but I still have a problem when the user clicks the back button on the browser. </p>
  
  <p>I was trying to prevent the user from going back by binding a pagebeforechange event to a function which, by looking at the URL of the destination page could know if the user is going back. This is kind of simple in my project since there are only 2 URLs accesible via the UI so any other URL would mean the user hit the back button. I'm using a regex due to the nature of the URL to validate this:</p>
  
  <pre><code>$( document ).bind('pagebeforechange', function(event, data) {  
  
    if(typeof data.toPage === "string") {
      var url = data.toPage;
      var regex = /.../
      var paramsIndex = url.indexOf('?'); // Get rid of possible params
  
      if(paramsIndex &gt; 0) {
        url = url.substr(0, paramsIndex);
      }
  
      if(regex.test(url)) {   
         event.preventDefault(); // Prevent the user from going back..
      }       
    }
  
  });
  </code></pre>
  
  <p>Unfortunately this doesn't work, even though the regex is working properly and matching everytime the user hits the back button (and only then). I was wondering if you have any ideas, I'd prefer to keep using the ajax navigation of jquery mobile.</p>
  
  <p>Cheers</p>