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

為{幸葍}努か 提交于 2019-12-22 10:19:07

问题


I am changing the page with this method

$.mobile.changePage("Preview.html", {
        transition : "slide",
        role : "page",
        changeHash:true                            
    });

this is how my preview page looks like

    <div data-role="page"  data-name="preview" class="prew">
        <div data-role="content">
            //content
       </div>
    </div>

now when i touch the screen i have to go back to previous page.

so i created this function

$('.prew').live('tap', function() {
         alert('clicked');
         history.go(-1);//<--this works in simulator not in device.
         //window.history.back() ;//<--this also works in simulator not on device.
         //navigator.app.backHistory();<--this works fine on android not on iOS.
    });

edit: i have used a plugin called photoswipe which causes the issue . the history.go(-1),history.back() or data-rel="back" works fine on other pages.

photoswipe is preventing from getting back to previous page.


回答1:


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
 });
});



回答2:


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").




回答3:


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>


来源:https://stackoverflow.com/questions/15630134/going-back-to-previous-page-works-in-simulator-not-on-ios-device-jquerymobile

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