How to navigate back one page using $.mobile.changePage

后端 未结 6 1194
长情又很酷
长情又很酷 2021-02-07 04:19

All of the JQuery Mobile documentation I can find about navigating backwards assumes I am going to do this using an anchor tag and suggest I add data-rel=\"back\" t

相关标签:
6条回答
  • 2021-02-07 04:58

    You are going back "two levels" because if you fire changePage programmatically via

    $.mobile.changePage('#next', { transition: 'pop' });
    

    and omit all the other options, you are triggering two functions:

    • changePage
    • hashChange

    Normally on a regular transition, the hashChange is blocked, while on backwards transitions, the changePage should be blocked (not sure here...). So in your case you have your (wanted) hashChange and an unwanted (changePage) transition.

    Check the JQM docs for the options you can pass along in your changePage call or look in the 1.0 source code #3140 for all available options. I would try also passing changeHash:false or fromHashChange:true along in your function call and see what happens.

    If you want to dig deeper you will have to look for ignoreNextHashChange and how its value changes though JQM.

    0 讨论(0)
  • 2021-02-07 04:59

    Add changeHash: true from where you are redirecting. And then use 'history.back()' or 'history.go(-1)' from your current page. It will only take you 1 page back.

    $.mobile.changePage("yourpage.html",{ transition: "flip", changeHash: true});
    
    0 讨论(0)
  • 2021-02-07 05:01

    A call to history.back() will do that.

    0 讨论(0)
  • 2021-02-07 05:06

    Why not just use data-rel="back" as an attribute to your back button, this will take the user back 1 page.

    Also equivalent to history.back()

    0 讨论(0)
  • 2021-02-07 05:19

    it makes sense to use data-rel="back" for something like that: <a href="#" data-rel="back" ...

    but it is better to use history.back(); inside javascript code blog i.e

    .....
    .....  
        var cId = $(this).val();
        // do something with control ID then
    .....
    .....
        goBackParent();
    }
    function goBackParent(){
         history.back();
    }
    
    0 讨论(0)
  • 2021-02-07 05:21

    It's definitely not clear in the documentation, but there are small allusions to it.

    Try using:

    $.mobile.back();
    
    0 讨论(0)
提交回复
热议问题