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

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.

Answers


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

Try using:

$.mobile.back();

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

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


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.


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


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

Need Your Help

ctags ignore lists for libc6, libstdc++ and boost

c++ c linux vim ctags

I use ctags with vim and the OmniCppComplete plugin. Currently when generating my tags I do it individually for each library. For libc6 I use the following list of tokens / macros in a file named...

C2DM: How to use C2D_MESSAGE permission?

android android-c2dm

I am about to implement C2DM for my application, but I find the documentation a bit confusing regarding how to write the manifest.