I have a PhoneGap App using jQuery Mobile.
At a certain page, I cannot let the user go back to the last page he visited.
The pages order is like this:
(1)index -> (2)listing items -> (3)form submited -> (4)sucess page
What I need: I want to clear all history when the user is at page 4 and set page 1 as it were the last and only visited in case of the user tries to go back. Maybe that’s not totally possible, then I would accept any suggestion.
I imagine jQuery Mobile stores navigation history in some kind of array, and I hope someone can help find that. Thanks in advance!
EDIT:
I’m using multi-page template, which is a single html page, where certain divs works as pages managed by jQuery Mobile.
Basically you have two history “pots” you need to tamper with. Browser and JQM.
JQM urlHistory
You can modify JQMs urlHistory very easily. From the JQM code:
So all of the above functions are available and can be called like this for example:
To monitor your history, put this somewhere and listen for pageChange (once transitions are done) to see what is inside the urlHistory:
From there you can start to see what should be in the history and clean it up as you need.
I’m using this a lot for my own navigation layer to modify what is stored in the urlHistory and what should not be stored. Sync-ing with the browser is the difficult part…
On sync-ing with the browser:
In my navigation layer I’m only removing double entries from the urlHistory, so there is always a page to go to (and not two), when you click the browser back button. In your case, you will presumable have 4 entries in the browser history, but if you remove 2 entries from JQM urlHistory, you will have two pages “not to got to” when the back button is clicked. So if your browser history looks like this:
And your remove page2 and page3, clicking back-button should result in:
A theoretical workaround would be:
Beware this is not an optimal solution and you have to consider a lot of things (user clicks somewhere else before going back etc). I tried forever to get something like this to work in a more complicated setup and eventually just stopped using it, because it never worked as it should. But for a simpler setup it may very well work.