Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery mobile changepage with back button not working

I have 4 pages within my JQM main HTML file. When I switch to one using changepage it's fine the first time, but I use a data-rel=back button to go back and this switches to the previous page but then bounces back to the page that has the back button. Should I just not use data-rel=back? If not what alternative is there?

Using JQM 1.3.1

$("#listView").on("vclick","li", function(e) {  
  //ajax call to get results for second page
  $.mobile.changePage('#second');
}

Button on second page

<a href="#" data-rel="back">Back</a>
like image 402
Jason Avatar asked Nov 03 '22 20:11

Jason


1 Answers

To go to previous page programmatically, use the below code. You need also to use stopImmediatePropagation(); to stop jQuery Mobile from jumping twice, which will result showing the same page.

Edit: I tested it on iPad, preventDefault() is required too.

Demo

$(document).on('vclick', '[data-rel=back]', function (e) {
 e.stopImmediatePropagation();
 e.preventDefault();
 var back = $.mobile.activePage.prev('[data-role=page]');
  $.mobile.changePage(back, { 
    transition: 'slide',
    reverse: true });
});
like image 128
Omar Avatar answered Nov 12 '22 15:11

Omar