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

只谈情不闲聊 提交于 2019-12-12 07:33:23

问题


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" to the tag.

I'm not navigating from a tag, I'm mixing with PhoneGap which means I'm calling javascript functions like PhoneGap.something(goForwardOnSuccess,goBackwardsOnFailure);

where

function goFowardOnSuccess()
{
    $.mobile.changePage('#next', { transition: 'pop' });
}
function goBackwardOnFailure()
{
    $.mobile.changePage(/* I HAVE NO IDEA WHAT GOES HERE */);
}

One of the main things I'm using this sort of thing for is putting up a "Busy Doing Something In Native Code Don't Touch Me..." click shield screen with the "loading" stuff and then closing it in the completion functions.

However, I find when I try that from a button on a screen I "popped" into place, I find myself back at the home page (goes back two levels).

The documentation is maddeningly vague about how to navigate backwards from pure javascript. Any clues would be very nice.

Notice also that I tend to pop these busy screens from everywhere so explicitly coding a transition back to the screen I want isn't really an option.


回答1:


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

Try using:

$.mobile.back();



回答2:


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



回答3:


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()




回答4:


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.




回答5:


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




回答6:


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


来源:https://stackoverflow.com/questions/8206108/how-to-navigate-back-one-page-using-mobile-changepage

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