Going back to previous page works in simulator not on iOS device jquerymobile

折月煮酒 提交于 2019-12-05 22:04:35

Here is a method you could use. However, pages should have a unique ID in order to have this working.

Test it here.

$('.prew').on('tap', function() {

 // get the ID of the previous page
 var previous = '#' + $.mobile.activePage.prev('div[data-role="page"]')[0].id;

 // move to previous page with reverse effect
 $.mobile.changePage(previous, {
    transition: 'slide',
    reverse: true
 });
});

I wouldn't recommend data-rel="back". With my experience this seem to cause problems (especially when user manually force reloads using ctrl + f5).

If you have handled the history properly then I would suggest you to use history.back() function.

$('.prew').live('tap', function() {
    alert('clicked');
    history.back();
});

Also I think its better to use ID than class in Page tag (e.g. id="prew").

So instead of using a javascript approach to go to previous page. Why not add data-rel="back" attribute to the button/link.

Everything then will be taken care by jQuery Mobile (JQM) itself.

<a href="#" data-rel="back">Back</a>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!