Alfredo Osorio
Alfredo Osorio

Reputation: 11475

Is it possible to go back to specified page id in jQuery mobile?

Suppose I have 4 pages with this page IDs:

pageA -> pageB -> pageC -> pageD

There can be an event in pageC and pageD that can make the application go back to pageB, the problem is that depending on the page I'm currently at I should call history.go(-N) where N is the number of pages that I should go back. For example if I am in pageD I should call history.go(-2), in case of pageC history.go(-1) to keep history consistently. How would you do that in jQuery Mobile so that history would contain:

pageA -> pageB

Another solution would be just to navigate to pageB directly with $("body").pagecontainer("change", "pageB.html") the problem with that is that the history chain would be wrong like this:

pageA -> pageB -> pageC -> pageD -> pageB

All pages have a back button that's why it is important to keep history chain consistently.

Upvotes: 1

Views: 219

Answers (2)

PeterKA
PeterKA

Reputation: 24648

You can use $.mobile.activePage.attr('id') to determine what page you're on then you can back up to the page you want having determined how many steps back you should go. Let me know if this is workable.

You may find this question useful too.

Upvotes: 1

ezanker
ezanker

Reputation: 24738

You can use the changeHash option to stop jQM from adding a history item:

http://api.jquerymobile.com/pagecontainer/#method-change

$("body").pagecontainer("change", "pageB.html", {changeHash: false});

Upvotes: 0

Related Questions