How to modify jQuery mobile history Back Button behavior

后端 未结 6 1416
忘了有多久
忘了有多久 2020-12-13 21:47

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.

I have a wine review webapp th

6条回答
  •  悲哀的现实
    2020-12-13 22:11

    Okay so the solution was close to the update I posted. The issue with the previous solution was that there were to many things bind-ed to the "Back" button. While my new bind action may have been working sometimes, the other actions would take place too, I tried unbind() but still no worky.

    My solution is a bit of smoke and mirrors. I check to see if the the previous page was the review page and then if so, I swap out the old back button for my new faux button with the history back step like so:

    $('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) )
        {
          $('a.ui-btn-left').replaceWith('Back');
    
          $('#time_machine').bind( 'click', function( ) {  
            console.log("click should be bound and going back in time...")
            window.history.go(-3);
            });
        }
      else
        {
          console.log('err nope its: ' + last_url);
        }
    

    It looks exactly the same, and no one is the wiser. it could probably be improved by using the the jQm method pagebeforeshow so user could never see the swap. Hope this helps someone.

提交回复
热议问题