title: How to modify jQuery mobile history Back Button behavior
body: <p>I'll start this off with I have researched a bit, but no solution that solves what seems like it should be a simple JQM modification.</p>
  
  <p>I have a wine review webapp that has the following view user flow:
  <a href="http://5buckchuck.com/" rel="noreferrer">http://5buckchuck.com/</a></p>
  
  <p>Wine type > Wine list > Wine Details > Wine review (redirect via django backto ) > Wine Details updated from review</p>
  
  <p>What I want to happen is when the user presses the back button it should go back to the wine list. What currently happens is the the Wine Detail view is reloaded. It takes pressing back three times to get back to the Wine List. :-(</p>
  
  <p>My thoughts to solve this were two:</p>
  
  <ol>
  <li><p>Splice the last 3 items from the history stack, if the last items in the history stack was  Wine Review. I had a hard time trying to introspect the last history object to get the pageURL. I have a feeling that this solution is a bit too fragile though.</p>
  
  <pre><code>var last_hist = $.mobile.urlHistory.getActive();
  last_hist.data.pageURL;
  </code></pre></li>
  <li><p>The second thought was to override the back button behavior so that the back button from the Wine Detail view would always go back to the Wine list view</p>
  
  <pre><code>$('div#wine_detail').live('pageshow',function(event, ui){      
    $("a.ui-btn-left").bind("click", function(){
      location.replace("/wines/{{wine.wine_type}}/#");
    });   
  });
  </code></pre></li>
  </ol>
  
  <p>There is probably a better way to do this, but I'm a bit out of ideas. </p>
  
  <p>Update:
  So I continue to hack on this with somewhat negligible results. On thing I have found was this is what I basically need to work: <code>window.history.go(-3)</code></p>
  
  <p>from the console it does exactly what I need.</p>
  
  <p>So I tried binding it the the back button like such:</p>
  
  <pre><code>$('div#wine_detail').live('pageshow',function(event, ui){
    var last = $.mobile.urlHistory.stack.length - 1;
    var last_url = $.mobile.urlHistory.stack[last].url;
    var review_url = /review/g;
     if (last_url.match(review_url) )
       {
         $('div#wine_detail a.ui-btn-left').bind( 'click', function( ) {  
           console.log("click should be bound and going back in time...")
           window.history.go(-2);
           });
     }
     else
     {
       console.log('err nope its: ' + last_url);
     }
   });
  </code></pre>
  
  <p>No dice, something interupts the transaction...</p>